@morpho-org/morpho-sdk 2.1.1 → 3.0.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/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/supplyCollateral.d.ts +2 -0
- package/lib/cjs/actions/marketV1/supplyCollateral.js +11 -12
- package/lib/cjs/actions/marketV1/supplyCollateralBorrow.d.ts +2 -0
- package/lib/cjs/actions/marketV1/supplyCollateralBorrow.js +13 -14
- 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 +555 -0
- package/lib/cjs/bundler/actions.js +953 -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 +181 -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 +45 -11
- package/lib/cjs/entities/marketV1/marketV1.js +27 -12
- 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 +48 -8
- package/lib/cjs/helpers/computeReallocations.js +120 -32
- package/lib/cjs/helpers/constant.d.ts +17 -0
- package/lib/cjs/helpers/constant.js +30 -1
- package/lib/cjs/helpers/index.d.ts +1 -0
- package/lib/cjs/helpers/index.js +9 -1
- package/lib/cjs/helpers/validate.d.ts +2 -0
- package/lib/cjs/helpers/validate.js +14 -2
- package/lib/cjs/index.d.ts +0 -1
- package/lib/cjs/index.js +0 -1
- package/lib/cjs/types/client.d.ts +1 -1
- package/lib/cjs/types/error.d.ts +87 -1
- package/lib/cjs/types/error.js +119 -1
- 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/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/supplyCollateral.d.ts +2 -0
- package/lib/esm/actions/marketV1/supplyCollateral.js +4 -5
- package/lib/esm/actions/marketV1/supplyCollateralBorrow.d.ts +2 -0
- package/lib/esm/actions/marketV1/supplyCollateralBorrow.js +4 -5
- 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 +555 -0
- package/lib/esm/bundler/actions.js +950 -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 +181 -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 +45 -11
- package/lib/esm/entities/marketV1/marketV1.js +28 -13
- 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 +48 -8
- package/lib/esm/helpers/computeReallocations.js +119 -31
- package/lib/esm/helpers/constant.d.ts +17 -0
- package/lib/esm/helpers/constant.js +30 -1
- package/lib/esm/helpers/index.d.ts +1 -0
- package/lib/esm/helpers/index.js +1 -0
- package/lib/esm/helpers/validate.d.ts +2 -0
- package/lib/esm/helpers/validate.js +12 -1
- package/lib/esm/index.d.ts +0 -1
- package/lib/esm/index.js +0 -1
- package/lib/esm/types/client.d.ts +1 -1
- package/lib/esm/types/error.d.ts +87 -1
- package/lib/esm/types/error.js +112 -0
- 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 +118 -11
- package/src/index.ts +0 -1
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import type { InputMarketParams } from "@morpho-org/blue-sdk";
|
|
2
|
+
import type { Address, Hex } from "viem";
|
|
3
|
+
/**
|
|
4
|
+
* Morpho authorization payload signed by a user for Bundler3-mediated Morpho
|
|
5
|
+
* Blue execution.
|
|
6
|
+
*/
|
|
7
|
+
export interface Authorization {
|
|
8
|
+
/** Address granting or revoking authorization. */
|
|
9
|
+
readonly authorizer: Address;
|
|
10
|
+
/** Address receiving authorization. */
|
|
11
|
+
readonly authorized: Address;
|
|
12
|
+
/** Whether authorization is granted (`true`) or revoked (`false`). */
|
|
13
|
+
readonly isAuthorized: boolean;
|
|
14
|
+
/** Morpho authorization nonce consumed by the signature. */
|
|
15
|
+
readonly nonce: bigint;
|
|
16
|
+
/** Signature deadline timestamp in seconds. */
|
|
17
|
+
readonly deadline: bigint;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Public allocator withdrawal input used by a `reallocateTo` Bundler3 action.
|
|
21
|
+
*/
|
|
22
|
+
export interface InputReallocation {
|
|
23
|
+
/** Market to withdraw liquidity from. */
|
|
24
|
+
readonly marketParams: InputMarketParams;
|
|
25
|
+
/** Amount of loan assets to withdraw from the market. */
|
|
26
|
+
readonly amount: bigint;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Permit2 single-permit token allowance details.
|
|
30
|
+
*/
|
|
31
|
+
export interface Permit2PermitSingleDetails {
|
|
32
|
+
/** ERC20 token approved through Permit2. */
|
|
33
|
+
readonly token: Address;
|
|
34
|
+
/** Allowance amount approved through Permit2. */
|
|
35
|
+
readonly amount: bigint;
|
|
36
|
+
/** Permit2 allowance expiration timestamp in seconds. */
|
|
37
|
+
readonly expiration: number;
|
|
38
|
+
/** Permit2 nonce consumed by the signature. */
|
|
39
|
+
readonly nonce: number;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Permit2 single-permit payload signed by the token owner.
|
|
43
|
+
*/
|
|
44
|
+
export interface Permit2PermitSingle {
|
|
45
|
+
/** Token, amount, expiration, and nonce being approved. */
|
|
46
|
+
readonly details: Permit2PermitSingleDetails;
|
|
47
|
+
/** Deadline timestamp for consuming the Permit2 signature. */
|
|
48
|
+
readonly sigDeadline: bigint;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Argument tuples for Bundler3 actions supported by `morpho-sdk`.
|
|
52
|
+
*/
|
|
53
|
+
export interface ActionArgs {
|
|
54
|
+
/** Native-token transfer from `owner` to `recipient` for `amount`; `skipRevert` controls Bundler3 revert handling. */
|
|
55
|
+
readonly nativeTransfer: [
|
|
56
|
+
owner: Address,
|
|
57
|
+
recipient: Address,
|
|
58
|
+
amount: bigint,
|
|
59
|
+
skipRevert?: boolean
|
|
60
|
+
];
|
|
61
|
+
/** ERC20 transfer from `adapter` to `recipient` for `amount` of `asset`; `skipRevert` controls Bundler3 revert handling. */
|
|
62
|
+
readonly erc20Transfer: [
|
|
63
|
+
asset: Address,
|
|
64
|
+
recipient: Address,
|
|
65
|
+
amount: bigint,
|
|
66
|
+
adapter: Address,
|
|
67
|
+
skipRevert?: boolean
|
|
68
|
+
];
|
|
69
|
+
/** GeneralAdapter1 ERC20 `transferFrom` of `asset` and `amount` to `recipient`; `skipRevert` controls Bundler3 revert handling. */
|
|
70
|
+
readonly erc20TransferFrom: [
|
|
71
|
+
asset: Address,
|
|
72
|
+
amount: bigint,
|
|
73
|
+
recipient: Address,
|
|
74
|
+
skipRevert?: boolean
|
|
75
|
+
];
|
|
76
|
+
/** ERC-2612 permit from `owner` for `asset`, `amount`, `deadline`, and `signature`; `skipRevert` controls Bundler3 revert handling. */
|
|
77
|
+
readonly permit: [
|
|
78
|
+
owner: Address,
|
|
79
|
+
asset: Address,
|
|
80
|
+
amount: bigint,
|
|
81
|
+
deadline: bigint,
|
|
82
|
+
signature: Hex | null,
|
|
83
|
+
skipRevert?: boolean
|
|
84
|
+
];
|
|
85
|
+
/** Permit2 approval from `owner` for `permitSingle` and `signature`; `skipRevert` controls Bundler3 revert handling. */
|
|
86
|
+
readonly approve2: [
|
|
87
|
+
owner: Address,
|
|
88
|
+
permitSingle: Permit2PermitSingle,
|
|
89
|
+
signature: Hex | null,
|
|
90
|
+
skipRevert?: boolean
|
|
91
|
+
];
|
|
92
|
+
/** GeneralAdapter1 Permit2 transfer of `asset` and `amount` to `recipient`; `skipRevert` controls Bundler3 revert handling. */
|
|
93
|
+
readonly transferFrom2: [
|
|
94
|
+
asset: Address,
|
|
95
|
+
amount: bigint,
|
|
96
|
+
recipient: Address,
|
|
97
|
+
skipRevert?: boolean
|
|
98
|
+
];
|
|
99
|
+
/** ERC4626 deposit into `erc4626` for `assets`, `maxSharePrice`, and `receiver`; `skipRevert` controls Bundler3 revert handling. */
|
|
100
|
+
readonly erc4626Deposit: [
|
|
101
|
+
erc4626: Address,
|
|
102
|
+
assets: bigint,
|
|
103
|
+
maxSharePrice: bigint,
|
|
104
|
+
receiver: Address,
|
|
105
|
+
skipRevert?: boolean
|
|
106
|
+
];
|
|
107
|
+
/** ERC4626 redeem from `erc4626` for `shares`, `minSharePrice`, `receiver`, and `owner`; `skipRevert` controls Bundler3 revert handling. */
|
|
108
|
+
readonly erc4626Redeem: [
|
|
109
|
+
erc4626: Address,
|
|
110
|
+
shares: bigint,
|
|
111
|
+
minSharePrice: bigint,
|
|
112
|
+
receiver: Address,
|
|
113
|
+
owner: Address,
|
|
114
|
+
skipRevert?: boolean
|
|
115
|
+
];
|
|
116
|
+
/** Morpho Blue supply-collateral call for `market`, `assets`, `onBehalf`, and callback actions; `skipRevert` controls Bundler3 revert handling. */
|
|
117
|
+
readonly morphoSupplyCollateral: [
|
|
118
|
+
market: InputMarketParams,
|
|
119
|
+
assets: bigint,
|
|
120
|
+
onBehalf: Address,
|
|
121
|
+
onMorphoSupplyCollateral: Action[],
|
|
122
|
+
skipRevert?: boolean
|
|
123
|
+
];
|
|
124
|
+
/** Morpho Blue borrow call for `market`, `assets` or `shares`, `slippageAmount`, and `receiver`; `skipRevert` controls Bundler3 revert handling. */
|
|
125
|
+
readonly morphoBorrow: [
|
|
126
|
+
market: InputMarketParams,
|
|
127
|
+
assets: bigint,
|
|
128
|
+
shares: bigint,
|
|
129
|
+
slippageAmount: bigint,
|
|
130
|
+
receiver: Address,
|
|
131
|
+
skipRevert?: boolean
|
|
132
|
+
];
|
|
133
|
+
/** Morpho Blue repay call for `market`, `assets` or `shares`, `slippageAmount`, `onBehalf`, and callback actions; `skipRevert` controls Bundler3 revert handling. */
|
|
134
|
+
readonly morphoRepay: [
|
|
135
|
+
market: InputMarketParams,
|
|
136
|
+
assets: bigint,
|
|
137
|
+
shares: bigint,
|
|
138
|
+
slippageAmount: bigint,
|
|
139
|
+
onBehalf: Address,
|
|
140
|
+
onMorphoRepay: Action[],
|
|
141
|
+
skipRevert?: boolean
|
|
142
|
+
];
|
|
143
|
+
/** Morpho Blue withdraw-collateral call for `market`, `assets`, and `receiver`; `skipRevert` controls Bundler3 revert handling. */
|
|
144
|
+
readonly morphoWithdrawCollateral: [
|
|
145
|
+
market: InputMarketParams,
|
|
146
|
+
assets: bigint,
|
|
147
|
+
receiver: Address,
|
|
148
|
+
skipRevert?: boolean
|
|
149
|
+
];
|
|
150
|
+
/** PublicAllocator reallocation to `supplyMarket` from `vault` withdrawals while paying `fee`; `skipRevert` controls Bundler3 revert handling. */
|
|
151
|
+
readonly reallocateTo: [
|
|
152
|
+
vault: Address,
|
|
153
|
+
fee: bigint,
|
|
154
|
+
withdrawals: InputReallocation[],
|
|
155
|
+
supplyMarket: InputMarketParams,
|
|
156
|
+
skipRevert?: boolean
|
|
157
|
+
];
|
|
158
|
+
/** GeneralAdapter1 native wrap of `amount` to `recipient`; `skipRevert` controls Bundler3 revert handling. */
|
|
159
|
+
readonly wrapNative: [
|
|
160
|
+
amount: bigint,
|
|
161
|
+
recipient: Address,
|
|
162
|
+
skipRevert?: boolean
|
|
163
|
+
];
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Supported Bundler3 action discriminator.
|
|
167
|
+
*/
|
|
168
|
+
export type ActionType = keyof ActionArgs;
|
|
169
|
+
/**
|
|
170
|
+
* Supported Bundler3 action object map keyed by action discriminator.
|
|
171
|
+
*/
|
|
172
|
+
export type Actions = {
|
|
173
|
+
readonly [T in ActionType]: {
|
|
174
|
+
readonly type: T;
|
|
175
|
+
readonly args: ActionArgs[T];
|
|
176
|
+
};
|
|
177
|
+
};
|
|
178
|
+
/**
|
|
179
|
+
* Discriminated union of Bundler3 actions supported by `morpho-sdk`.
|
|
180
|
+
*/
|
|
181
|
+
export type Action = Actions[ActionType];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { ChainId, ChainUtils, DEFAULT_SLIPPAGE_TOLERANCE, EIP_712_FIELDS, isMarketId, LIQUIDATION_CURSOR, MAX_LIQUIDATION_INCENTIVE_FACTOR, ORACLE_PRICE_SCALE, SECONDS_PER_YEAR, TransactionType, } from "@morpho-org/blue-sdk";
|
|
2
|
+
export { BLUE_API_BASE_URL, BLUE_API_GRAPHQL_URL, CDN_BASE_URL, DOCS_BASE_URL, MORPHO_DOMAIN, OPTIMIZERS_API_BASE_URL, OPTIMIZERS_BASE_URL, REWARDS_BASE_URL, ZERO_ADDRESS, } from "@morpho-org/morpho-ts";
|
|
3
|
+
export { APPROVE_ONLY_ONCE_TOKENS, DEFAULT_LLTV_BUFFER, DEFAULT_SUPPLY_TARGET_UTILIZATION, DEFAULT_WITHDRAWAL_TARGET_UTILIZATION, MAX_ABSOLUTE_SHARE_PRICE, MAX_SLIPPAGE_TOLERANCE, MAX_TOKEN_APPROVALS, } from "./helpers/constant.js";
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { ChainId, ChainUtils, DEFAULT_SLIPPAGE_TOLERANCE, EIP_712_FIELDS, isMarketId, LIQUIDATION_CURSOR, MAX_LIQUIDATION_INCENTIVE_FACTOR, ORACLE_PRICE_SCALE, SECONDS_PER_YEAR, TransactionType, } from "@morpho-org/blue-sdk";
|
|
2
|
+
export { BLUE_API_BASE_URL, BLUE_API_GRAPHQL_URL, CDN_BASE_URL, DOCS_BASE_URL, MORPHO_DOMAIN, OPTIMIZERS_API_BASE_URL, OPTIMIZERS_BASE_URL, REWARDS_BASE_URL, ZERO_ADDRESS, } from "@morpho-org/morpho-ts";
|
|
3
|
+
export { APPROVE_ONLY_ONCE_TOKENS, DEFAULT_LLTV_BUFFER, DEFAULT_SUPPLY_TARGET_UTILIZATION, DEFAULT_WITHDRAWAL_TARGET_UTILIZATION, MAX_ABSOLUTE_SHARE_PRICE, MAX_SLIPPAGE_TOLERANCE, MAX_TOKEN_APPROVALS, } from "./helpers/constant.js";
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
1
|
+
export type { IAccrualPosition, IAccrualVault, IAccrualVaultV2, IAccrualVaultV2Adapter, IAccrualVaultV2MorphoMarketV1Adapter, IAccrualVaultV2MorphoMarketV1AdapterV2, IAccrualVaultV2MorphoVaultV1Adapter, IAssetBalances, IEip5267Domain, IHolding, IMarket, IMarketParams, IPosition, IPreLiquidationParams, IPreLiquidationPosition, IToken, IVault, IVaultConfig, IVaultMarketAllocation, IVaultMarketConfig, IVaultMarketPublicAllocatorConfig, IVaultToken, IVaultUser, IVaultV2, IVaultV2Adapter, IVaultV2Allocation, IVaultV2MorphoMarketV1Adapter, IVaultV2MorphoMarketV1AdapterV2, IVaultV2MorphoVaultV1Adapter, PeripheralBalance, PeripheralBalanceType, VaultPublicAllocatorConfig, } from "@morpho-org/blue-sdk";
|
|
2
|
+
export { AccrualPosition, AccrualVault, AccrualVaultV2, AccrualVaultV2MorphoMarketV1Adapter, AccrualVaultV2MorphoMarketV1AdapterV2, AccrualVaultV2MorphoVaultV1Adapter, AssetBalances, ConstantWrappedToken, Eip5267Domain, ExchangeRateWrappedToken, Holding, Market, MarketParams, Position, PreLiquidationParams, PreLiquidationPosition, Token, User, Vault, VaultConfig, VaultMarketAllocation, VaultMarketConfig, VaultMarketPublicAllocatorConfig, VaultToken, VaultUser, VaultV2, VaultV2Adapter, VaultV2MorphoMarketV1Adapter, VaultV2MorphoMarketV1AdapterV2, VaultV2MorphoVaultV1Adapter, WrappedToken, } from "@morpho-org/blue-sdk";
|
|
3
|
+
export { MorphoMarketV1 } from "./marketV1/index.js";
|
|
4
|
+
export { type InputReallocationData, ReallocationData, } from "./reallocationData.js";
|
|
5
|
+
export { MorphoVaultV1 } from "./vaultV1/index.js";
|
|
6
|
+
export { MorphoVaultV2 } from "./vaultV2/index.js";
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
1
|
+
export { AccrualPosition, AccrualVault, AccrualVaultV2, AccrualVaultV2MorphoMarketV1Adapter, AccrualVaultV2MorphoMarketV1AdapterV2, AccrualVaultV2MorphoVaultV1Adapter, AssetBalances, ConstantWrappedToken, Eip5267Domain, ExchangeRateWrappedToken, Holding, Market, MarketParams, Position, PreLiquidationParams, PreLiquidationPosition, Token, User, Vault, VaultConfig, VaultMarketAllocation, VaultMarketConfig, VaultMarketPublicAllocatorConfig, VaultToken, VaultUser, VaultV2, VaultV2Adapter, VaultV2MorphoMarketV1Adapter, VaultV2MorphoMarketV1AdapterV2, VaultV2MorphoVaultV1Adapter, WrappedToken, } from "@morpho-org/blue-sdk";
|
|
2
|
+
export { MorphoMarketV1 } from "./marketV1/index.js";
|
|
3
|
+
export { ReallocationData, } from "./reallocationData.js";
|
|
4
|
+
export { MorphoVaultV1 } from "./vaultV1/index.js";
|
|
5
|
+
export { MorphoVaultV2 } from "./vaultV2/index.js";
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { type AccrualPosition, type Market, type MarketParams } from "@morpho-org/blue-sdk";
|
|
2
|
-
import { type MinimalBlock, SimulationState } from "@morpho-org/simulation-sdk";
|
|
3
2
|
import type { Address } from "viem";
|
|
4
3
|
import type { FetchParameters } from "../../types/data.js";
|
|
5
4
|
import { type DepositAmountArgs, type ERC20ApprovalAction, type MarketV1BorrowAction, type MarketV1RepayAction, type MarketV1RepayWithdrawCollateralAction, type MarketV1SupplyCollateralAction, type MarketV1SupplyCollateralBorrowAction, type MarketV1WithdrawCollateralAction, type MorphoAuthorizationAction, type MorphoClientType, type ReallocationComputeOptions, type RepayAmountArgs, type Requirement, type RequirementSignature, type Transaction, type VaultReallocation } from "../../types/index.js";
|
|
5
|
+
import { ReallocationData } from "../reallocationData.js";
|
|
6
6
|
export interface MarketV1Actions {
|
|
7
7
|
/**
|
|
8
8
|
* Fetches the latest market data with accrued interest.
|
|
@@ -173,7 +173,7 @@ export interface MarketV1Actions {
|
|
|
173
173
|
}) => Promise<(Readonly<Transaction<ERC20ApprovalAction>> | Readonly<Transaction<MorphoAuthorizationAction>> | Requirement)[]>;
|
|
174
174
|
};
|
|
175
175
|
/**
|
|
176
|
-
* Fetches all on-chain data needed to construct a {@link
|
|
176
|
+
* Fetches all on-chain data needed to construct a {@link ReallocationData}
|
|
177
177
|
* for computing vault reallocations via the public allocator.
|
|
178
178
|
*
|
|
179
179
|
* The target market is refetched internally at `block.number` so the
|
|
@@ -182,7 +182,7 @@ export interface MarketV1Actions {
|
|
|
182
182
|
* inject unnecessary `reallocateTo` actions (and their PublicAllocator
|
|
183
183
|
* fees) into the resulting bundle.
|
|
184
184
|
*
|
|
185
|
-
* The returned
|
|
185
|
+
* The returned reallocation data can be passed to {@link getReallocations}
|
|
186
186
|
* to compute the `VaultReallocation[]` array for `borrow()` or
|
|
187
187
|
* `supplyCollateralBorrow()`.
|
|
188
188
|
*
|
|
@@ -190,12 +190,16 @@ export interface MarketV1Actions {
|
|
|
190
190
|
*
|
|
191
191
|
* @param params.vaultAddresses - Addresses of MetaMorpho vaults that allocate to this market.
|
|
192
192
|
* @param params.block - The block to fetch data at (number and timestamp).
|
|
193
|
-
* @returns A
|
|
193
|
+
* @returns A ReallocationData instance populated with all required data.
|
|
194
|
+
* @throws {ChainIdMismatchError} when the client chain does not match this market.
|
|
194
195
|
*/
|
|
195
196
|
getReallocationData: (params: {
|
|
196
197
|
vaultAddresses: readonly Address[];
|
|
197
|
-
block:
|
|
198
|
-
|
|
198
|
+
block: {
|
|
199
|
+
readonly number: bigint;
|
|
200
|
+
readonly timestamp: bigint;
|
|
201
|
+
};
|
|
202
|
+
}) => Promise<ReallocationData>;
|
|
199
203
|
/**
|
|
200
204
|
* Computes vault reallocations for a borrow on this market.
|
|
201
205
|
*
|
|
@@ -206,12 +210,17 @@ export interface MarketV1Actions {
|
|
|
206
210
|
* @param params.reallocationData - The current on-chain state (from {@link getReallocationData}).
|
|
207
211
|
* @param params.borrowAmount - The intended borrow amount.
|
|
208
212
|
* @param params.options - Optional reallocation computation options
|
|
209
|
-
* (utilization targets, reallocatable vaults filter, etc.).
|
|
213
|
+
* (timestamp, utilization targets, reallocatable vaults filter, etc.).
|
|
214
|
+
* Pass the fetched block timestamp to compute reallocations at the same block.
|
|
210
215
|
* @returns Array of vault reallocations ready to pass to `borrow()` or
|
|
211
216
|
* `supplyCollateralBorrow()`. Empty array if no reallocation is needed.
|
|
217
|
+
* @throws {ChainIdMismatchError} when `reallocationData` belongs to a different chain than this market.
|
|
218
|
+
* @throws {InsufficientSharedLiquidityError} when shared liquidity cannot cover the borrow shortfall on the target market.
|
|
219
|
+
* @throws {MissingPublicAllocatorConfigError} when a selected vault is missing its public allocator config.
|
|
220
|
+
* @throws {UnknownReallocationMarketError} when the target market is absent from the reallocation data.
|
|
212
221
|
*/
|
|
213
222
|
getReallocations: (params: {
|
|
214
|
-
reallocationData:
|
|
223
|
+
reallocationData: ReallocationData;
|
|
215
224
|
borrowAmount: bigint;
|
|
216
225
|
options?: ReallocationComputeOptions;
|
|
217
226
|
}) => readonly VaultReallocation[];
|
|
@@ -281,12 +290,37 @@ export declare class MorphoMarketV1 implements MarketV1Actions {
|
|
|
281
290
|
}) => Promise<(Requirement | Readonly<Transaction<ERC20ApprovalAction>> | Readonly<Transaction<MorphoAuthorizationAction>>)[]>;
|
|
282
291
|
buildTx: (requirementSignature?: RequirementSignature) => Readonly<Transaction<MarketV1SupplyCollateralBorrowAction>>;
|
|
283
292
|
};
|
|
293
|
+
/**
|
|
294
|
+
* Fetches all on-chain inputs needed to compute public allocator reallocations.
|
|
295
|
+
*
|
|
296
|
+
* @param params - Reallocation data fetch parameters.
|
|
297
|
+
* @param params.vaultAddresses - Vaults to inspect for source-market liquidity.
|
|
298
|
+
* @param params.block - Block number and timestamp used for consistent RPC reads.
|
|
299
|
+
* @returns Reallocation data ready for {@link getReallocations}.
|
|
300
|
+
* @throws {ChainIdMismatchError} when the client chain does not match this market.
|
|
301
|
+
*/
|
|
284
302
|
getReallocationData({ vaultAddresses, block, }: {
|
|
285
303
|
vaultAddresses: readonly Address[];
|
|
286
|
-
block:
|
|
287
|
-
|
|
304
|
+
block: {
|
|
305
|
+
readonly number: bigint;
|
|
306
|
+
readonly timestamp: bigint;
|
|
307
|
+
};
|
|
308
|
+
}): Promise<ReallocationData>;
|
|
309
|
+
/**
|
|
310
|
+
* Computes public allocator reallocations for a borrow on this market.
|
|
311
|
+
*
|
|
312
|
+
* @param params - Reallocation computation parameters.
|
|
313
|
+
* @param params.reallocationData - State returned by {@link getReallocationData}.
|
|
314
|
+
* @param params.borrowAmount - Borrow amount to test against post-borrow utilization.
|
|
315
|
+
* @param params.options - Optional allocator and utilization options.
|
|
316
|
+
* @returns Vault reallocations ready to pass to `borrow` or `supplyCollateralBorrow`.
|
|
317
|
+
* @throws {ChainIdMismatchError} when `reallocationData` belongs to a different chain than this market.
|
|
318
|
+
* @throws {InsufficientSharedLiquidityError} when shared liquidity cannot cover the borrow shortfall on the target market.
|
|
319
|
+
* @throws {MissingPublicAllocatorConfigError} when a selected vault is missing its public allocator config.
|
|
320
|
+
* @throws {UnknownReallocationMarketError} when the target market is absent from the reallocation data.
|
|
321
|
+
*/
|
|
288
322
|
getReallocations({ reallocationData, borrowAmount, options, }: {
|
|
289
|
-
reallocationData:
|
|
323
|
+
reallocationData: ReallocationData;
|
|
290
324
|
borrowAmount: bigint;
|
|
291
325
|
options?: ReallocationComputeOptions;
|
|
292
326
|
}): readonly VaultReallocation[];
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { DEFAULT_SLIPPAGE_TOLERANCE, MathLib, } from "@morpho-org/blue-sdk";
|
|
2
|
-
import { fetchAccrualPosition,
|
|
2
|
+
import { fetchAccrualPosition, fetchMarket, fetchPosition, fetchVault, fetchVaultMarketConfig, } from "@morpho-org/blue-sdk-viem";
|
|
3
3
|
import { Time } from "@morpho-org/morpho-ts";
|
|
4
|
-
import { SimulationState } from "@morpho-org/simulation-sdk";
|
|
5
4
|
import { getMorphoAuthorizationRequirement, getRequirements, marketV1Borrow, marketV1Repay, marketV1RepayWithdrawCollateral, marketV1SupplyCollateral, marketV1SupplyCollateralBorrow, marketV1WithdrawCollateral, } from "../../actions/index.js";
|
|
6
5
|
import { computeMaxRepaySharePrice, computeMinBorrowSharePrice, computeReallocations, validateAccrualPosition, validateChainId, validateNativeCollateral, validatePositionHealth, validatePositionHealthAfterWithdraw, validateRepayAmount, validateRepayShares, validateSlippageTolerance, } from "../../helpers/index.js";
|
|
7
6
|
import { MissingAccrualPositionError, MutuallyExclusiveRepayAmountsError, NegativeNativeAmountError, NonPositiveAssetAmountError, NonPositiveBorrowAmountError, NonPositiveRepayAmountError, NonPositiveWithdrawCollateralAmountError, WithdrawExceedsCollateralError, ZeroCollateralAmountError, } from "../../types/index.js";
|
|
7
|
+
import { ReallocationData } from "../reallocationData.js";
|
|
8
8
|
export class MorphoMarketV1 {
|
|
9
9
|
client;
|
|
10
10
|
marketParams;
|
|
@@ -444,6 +444,15 @@ export class MorphoMarketV1 {
|
|
|
444
444
|
}),
|
|
445
445
|
};
|
|
446
446
|
}
|
|
447
|
+
/**
|
|
448
|
+
* Fetches all on-chain inputs needed to compute public allocator reallocations.
|
|
449
|
+
*
|
|
450
|
+
* @param params - Reallocation data fetch parameters.
|
|
451
|
+
* @param params.vaultAddresses - Vaults to inspect for source-market liquidity.
|
|
452
|
+
* @param params.block - Block number and timestamp used for consistent RPC reads.
|
|
453
|
+
* @returns Reallocation data ready for {@link getReallocations}.
|
|
454
|
+
* @throws {ChainIdMismatchError} when the client chain does not match this market.
|
|
455
|
+
*/
|
|
447
456
|
async getReallocationData({ vaultAddresses, block, }) {
|
|
448
457
|
validateChainId(this.client.viemClient.chain?.id, this.chainId);
|
|
449
458
|
const client = this.client.viemClient;
|
|
@@ -475,8 +484,7 @@ export class MorphoMarketV1 {
|
|
|
475
484
|
}
|
|
476
485
|
// Phase 2: Fetch all source markets, vault configs, and positions in parallel.
|
|
477
486
|
const sourceMarketIds = [...allMarketIds].filter((mid) => mid !== targetMarketId);
|
|
478
|
-
const
|
|
479
|
-
const [markets, configs, positions, holdings] = await Promise.all([
|
|
487
|
+
const [markets, configs, positions] = await Promise.all([
|
|
480
488
|
Promise.all(sourceMarketIds.map((mid) => fetchMarket(mid, client, fetchParams))),
|
|
481
489
|
Promise.all(vaultMarketPairs.map(({ vault, marketId: mid }) => fetchVaultMarketConfig(vault, mid, client, fetchParams).then((config) => ({ vault, mid, config })))),
|
|
482
490
|
Promise.all(vaultMarketPairs.map(({ vault, marketId: mid }) => fetchPosition(vault, mid, client, fetchParams).then((position) => ({
|
|
@@ -484,9 +492,8 @@ export class MorphoMarketV1 {
|
|
|
484
492
|
mid,
|
|
485
493
|
position,
|
|
486
494
|
})))),
|
|
487
|
-
Promise.all(vaultAddresses.map((addr) => fetchHolding(addr, loanToken, client, fetchParams))),
|
|
488
495
|
]);
|
|
489
|
-
// Assemble records for
|
|
496
|
+
// Assemble records for ReallocationData.
|
|
490
497
|
const marketsRecord = {
|
|
491
498
|
[targetMarketId]: targetMarket,
|
|
492
499
|
};
|
|
@@ -505,21 +512,29 @@ export class MorphoMarketV1 {
|
|
|
505
512
|
for (const { vault, mid, position } of positions) {
|
|
506
513
|
(positionsRecord[vault] ??= {})[mid] = position;
|
|
507
514
|
}
|
|
508
|
-
|
|
509
|
-
for (const holding of holdings) {
|
|
510
|
-
(holdingsRecord[holding.user] ??= {})[holding.token] = holding;
|
|
511
|
-
}
|
|
512
|
-
return new SimulationState({
|
|
515
|
+
return new ReallocationData({
|
|
513
516
|
chainId: this.chainId,
|
|
514
|
-
block,
|
|
515
517
|
markets: marketsRecord,
|
|
516
518
|
vaults: vaultsRecord,
|
|
517
519
|
vaultMarketConfigs: vaultMarketConfigsRecord,
|
|
518
520
|
positions: positionsRecord,
|
|
519
|
-
holdings: holdingsRecord,
|
|
520
521
|
});
|
|
521
522
|
}
|
|
523
|
+
/**
|
|
524
|
+
* Computes public allocator reallocations for a borrow on this market.
|
|
525
|
+
*
|
|
526
|
+
* @param params - Reallocation computation parameters.
|
|
527
|
+
* @param params.reallocationData - State returned by {@link getReallocationData}.
|
|
528
|
+
* @param params.borrowAmount - Borrow amount to test against post-borrow utilization.
|
|
529
|
+
* @param params.options - Optional allocator and utilization options.
|
|
530
|
+
* @returns Vault reallocations ready to pass to `borrow` or `supplyCollateralBorrow`.
|
|
531
|
+
* @throws {ChainIdMismatchError} when `reallocationData` belongs to a different chain than this market.
|
|
532
|
+
* @throws {InsufficientSharedLiquidityError} when shared liquidity cannot cover the borrow shortfall on the target market.
|
|
533
|
+
* @throws {MissingPublicAllocatorConfigError} when a selected vault is missing its public allocator config.
|
|
534
|
+
* @throws {UnknownReallocationMarketError} when the target market is absent from the reallocation data.
|
|
535
|
+
*/
|
|
522
536
|
getReallocations({ reallocationData, borrowAmount, options, }) {
|
|
537
|
+
validateChainId(reallocationData.chainId, this.chainId);
|
|
523
538
|
return computeReallocations({
|
|
524
539
|
reallocationData,
|
|
525
540
|
marketId: this.marketParams.id,
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { AccrualPosition, Market, type MarketId, Position, Vault, VaultMarketConfig } from "@morpho-org/blue-sdk";
|
|
2
|
+
import type { Address } from "viem";
|
|
3
|
+
import type { PublicAllocatorOptions, PublicReallocation } from "../types/index.js";
|
|
4
|
+
/**
|
|
5
|
+
* Input state required to construct {@link ReallocationData}.
|
|
6
|
+
*/
|
|
7
|
+
export interface InputReallocationData {
|
|
8
|
+
/** Chain id associated with the fetched state. */
|
|
9
|
+
readonly chainId: number;
|
|
10
|
+
/** Markets indexed by market id. */
|
|
11
|
+
readonly markets?: Readonly<Record<MarketId, Market | undefined>>;
|
|
12
|
+
/** Vaults indexed by vault address. */
|
|
13
|
+
readonly vaults?: Readonly<Record<Address, Vault | undefined>>;
|
|
14
|
+
/** Positions indexed by user or vault address, then by market id. */
|
|
15
|
+
readonly positions?: Readonly<Record<Address, Readonly<Record<MarketId, Position | undefined>>>>;
|
|
16
|
+
/** Vault market configs indexed by vault address, then by market id. */
|
|
17
|
+
readonly vaultMarketConfigs?: Readonly<Record<Address, Readonly<Record<MarketId, VaultMarketConfig | undefined>>>>;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Narrow state container for computing public allocator reallocations.
|
|
21
|
+
*
|
|
22
|
+
* @remarks
|
|
23
|
+
* The class owns only the market, vault, position, vault-market-config,
|
|
24
|
+
* and chain data needed by the shared-liquidity algorithm. Constructor inputs
|
|
25
|
+
* are cloned, and simulation steps return cloned `ReallocationData` instances
|
|
26
|
+
* so fetched caller inputs are not mutated.
|
|
27
|
+
*
|
|
28
|
+
* Public records are exposed for inspection and snapshotting only. Treat
|
|
29
|
+
* `markets`, `vaults`, `positions`, and `vaultMarketConfigs` as a read
|
|
30
|
+
* contract keyed by market id or address; use the getters for typed absence
|
|
31
|
+
* errors and use simulation methods to produce updated state.
|
|
32
|
+
*/
|
|
33
|
+
export declare class ReallocationData implements InputReallocationData {
|
|
34
|
+
/** Chain id associated with the fetched reallocation data. */
|
|
35
|
+
readonly chainId: number;
|
|
36
|
+
/** Markets indexed by market id. */
|
|
37
|
+
readonly markets: Record<MarketId, Market | undefined>;
|
|
38
|
+
/** Vaults indexed by vault address. */
|
|
39
|
+
readonly vaults: Record<Address, Vault | undefined>;
|
|
40
|
+
/** Positions indexed by user or vault address, then by market id. */
|
|
41
|
+
readonly positions: Record<Address, Record<MarketId, Position | undefined>>;
|
|
42
|
+
/** Vault market configs indexed by vault address, then by market id. */
|
|
43
|
+
readonly vaultMarketConfigs: Record<Address, Record<MarketId, VaultMarketConfig | undefined>>;
|
|
44
|
+
/**
|
|
45
|
+
* Creates a cloned reallocation state from fetched market, vault, position,
|
|
46
|
+
* and vault-market-config data.
|
|
47
|
+
*
|
|
48
|
+
* @param input - Reallocation input data fetched at a consistent chain state.
|
|
49
|
+
*/
|
|
50
|
+
constructor(input: InputReallocationData);
|
|
51
|
+
/**
|
|
52
|
+
* Creates a deep clone of this reallocation state.
|
|
53
|
+
*
|
|
54
|
+
* @returns A new `ReallocationData` instance with cloned entity objects.
|
|
55
|
+
*/
|
|
56
|
+
clone(): ReallocationData;
|
|
57
|
+
private forkAliasedState;
|
|
58
|
+
/**
|
|
59
|
+
* Gets a market by id.
|
|
60
|
+
*
|
|
61
|
+
* @param marketId - Market id to read.
|
|
62
|
+
* @returns The cloned market data.
|
|
63
|
+
* @throws {@link UnknownReallocationMarketError} when the market is absent.
|
|
64
|
+
*/
|
|
65
|
+
getMarket(marketId: MarketId): Market;
|
|
66
|
+
/**
|
|
67
|
+
* Gets a vault by address.
|
|
68
|
+
*
|
|
69
|
+
* @param vault - Vault address to read.
|
|
70
|
+
* @returns The cloned vault data.
|
|
71
|
+
* @throws {@link UnknownReallocationVaultError} when the vault is absent.
|
|
72
|
+
*/
|
|
73
|
+
getVault(vault: Address): Vault;
|
|
74
|
+
/**
|
|
75
|
+
* Gets a raw market position.
|
|
76
|
+
*
|
|
77
|
+
* @param user - Position owner address, usually a MetaMorpho vault.
|
|
78
|
+
* @param marketId - Market id for the position.
|
|
79
|
+
* @returns The cloned position data.
|
|
80
|
+
* @throws {@link UnknownReallocationPositionError} when the position is absent.
|
|
81
|
+
*/
|
|
82
|
+
getPosition(user: Address, marketId: MarketId): Position;
|
|
83
|
+
/**
|
|
84
|
+
* Gets a position wrapped with its market accrual helpers.
|
|
85
|
+
*
|
|
86
|
+
* @param user - Position owner address, usually a MetaMorpho vault.
|
|
87
|
+
* @param marketId - Market id for the position.
|
|
88
|
+
* @returns Accrual-aware position data.
|
|
89
|
+
* @throws {@link UnknownReallocationPositionError} when the position is absent.
|
|
90
|
+
* @throws {@link UnknownReallocationMarketError} when the market is absent.
|
|
91
|
+
*/
|
|
92
|
+
getAccrualPosition(user: Address, marketId: MarketId): AccrualPosition;
|
|
93
|
+
/**
|
|
94
|
+
* Gets a vault-market config.
|
|
95
|
+
*
|
|
96
|
+
* @param vault - Vault address.
|
|
97
|
+
* @param marketId - Market id configured by the vault.
|
|
98
|
+
* @returns The cloned vault-market config.
|
|
99
|
+
* @throws {@link UnknownReallocationVaultMarketConfigError} when the config is absent.
|
|
100
|
+
*/
|
|
101
|
+
getVaultMarketConfig(vault: Address, marketId: MarketId): VaultMarketConfig;
|
|
102
|
+
/**
|
|
103
|
+
* Calculates public reallocations that can supply liquidity to `marketId`.
|
|
104
|
+
*
|
|
105
|
+
* @remarks
|
|
106
|
+
* The algorithm repeatedly chooses the single largest currently available
|
|
107
|
+
* source-market withdrawal across reallocatable vaults, applies that
|
|
108
|
+
* withdrawal to a cloned state, and repeats until no valid withdrawal remains.
|
|
109
|
+
*
|
|
110
|
+
* Pass `options.timestamp` to evaluate market interest and pending public
|
|
111
|
+
* allocator caps at the same block as the fetched reallocation data.
|
|
112
|
+
* This method does not add the legacy one-hour delay margin that
|
|
113
|
+
* `SimulationState.getMarketPublicReallocations` applied before measuring
|
|
114
|
+
* target-market vault headroom. If a transaction may land later than the
|
|
115
|
+
* fetched block, pass a future `timestamp` or reserve your own headroom so
|
|
116
|
+
* interest accrued before inclusion does not make `reallocateTo` exceed the
|
|
117
|
+
* target market cap.
|
|
118
|
+
* Returned `data` normalizes `vault.publicAllocatorConfig.accruedFee` to the
|
|
119
|
+
* on-chain `reallocateTo` fee semantics: one fee charge per vault with at
|
|
120
|
+
* least one computed withdrawal.
|
|
121
|
+
*
|
|
122
|
+
* @param marketId - Target market to supply with shared liquidity.
|
|
123
|
+
* @param options - Optional allocator discovery options.
|
|
124
|
+
* @returns Computed source-market withdrawals and the post-reallocation state.
|
|
125
|
+
* @throws {@link UnknownReallocationMarketError} when the target market is absent.
|
|
126
|
+
* @example
|
|
127
|
+
* ```ts
|
|
128
|
+
* import { createPublicClient, http } from "viem";
|
|
129
|
+
* import { mainnet } from "viem/chains";
|
|
130
|
+
* import { markets, vaults } from "@morpho-org/morpho-test";
|
|
131
|
+
* import {
|
|
132
|
+
* morphoViemExtension,
|
|
133
|
+
* type PublicReallocation,
|
|
134
|
+
* } from "@morpho-org/morpho-sdk";
|
|
135
|
+
* import type { ReallocationData } from "@morpho-org/morpho-sdk/entities";
|
|
136
|
+
*
|
|
137
|
+
* const client = createPublicClient({
|
|
138
|
+
* chain: mainnet,
|
|
139
|
+
* transport: http(),
|
|
140
|
+
* }).extend(morphoViemExtension());
|
|
141
|
+
*
|
|
142
|
+
* const marketParams = markets[mainnet.id].usdc_wbtc;
|
|
143
|
+
* const market = client.morpho.marketV1(marketParams, mainnet.id);
|
|
144
|
+
* const block = await client.getBlock();
|
|
145
|
+
* const reallocationData = await market.getReallocationData({
|
|
146
|
+
* vaultAddresses: [vaults[mainnet.id].steakUsdc.address],
|
|
147
|
+
* block: { number: block.number, timestamp: block.timestamp },
|
|
148
|
+
* });
|
|
149
|
+
*
|
|
150
|
+
* const result: {
|
|
151
|
+
* withdrawals: readonly PublicReallocation[];
|
|
152
|
+
* data: ReallocationData;
|
|
153
|
+
* } = reallocationData.getMarketPublicReallocations(marketParams.id, {
|
|
154
|
+
* timestamp: block.timestamp,
|
|
155
|
+
* });
|
|
156
|
+
* ```
|
|
157
|
+
*/
|
|
158
|
+
getMarketPublicReallocations(marketId: MarketId, options?: PublicAllocatorOptions): {
|
|
159
|
+
readonly withdrawals: readonly PublicReallocation[];
|
|
160
|
+
data: ReallocationData;
|
|
161
|
+
};
|
|
162
|
+
/**
|
|
163
|
+
* Gets the largest currently valid source-market withdrawal for a vault.
|
|
164
|
+
*
|
|
165
|
+
* @param params - Candidate vault, target market, prior withdrawals, and allocator limits.
|
|
166
|
+
* @returns The largest withdrawal candidate, or `undefined` if required data is missing.
|
|
167
|
+
*
|
|
168
|
+
* @internal
|
|
169
|
+
*/
|
|
170
|
+
private getLargestVaultWithdrawal;
|
|
171
|
+
/**
|
|
172
|
+
* Applies one public allocator withdrawal and corresponding target-market supply.
|
|
173
|
+
*
|
|
174
|
+
* @param vault - Vault performing the public reallocation.
|
|
175
|
+
* @param supplyMarketId - Target market that receives the withdrawn assets.
|
|
176
|
+
* @param withdrawal - Source market id and asset amount to withdraw.
|
|
177
|
+
* @param timestamp - Timestamp used to accrue source and target positions.
|
|
178
|
+
* @returns A cloned state after applying the simulated reallocation.
|
|
179
|
+
* @throws {@link MissingPublicAllocatorConfigError} when the vault allocator config is absent.
|
|
180
|
+
* @throws {@link UnknownReallocationVaultMarketConfigError} when source or target allocator limits are absent.
|
|
181
|
+
*
|
|
182
|
+
* @internal
|
|
183
|
+
*/
|
|
184
|
+
protected applyPublicReallocation({ vault, supplyMarketId, withdrawal, timestamp, }: {
|
|
185
|
+
readonly vault: Address;
|
|
186
|
+
readonly supplyMarketId: MarketId;
|
|
187
|
+
readonly withdrawal: {
|
|
188
|
+
readonly id: MarketId;
|
|
189
|
+
readonly assets: bigint;
|
|
190
|
+
};
|
|
191
|
+
readonly timestamp: bigint;
|
|
192
|
+
}): ReallocationData;
|
|
193
|
+
}
|