@morpho-org/morpho-sdk 5.9.0 → 6.0.0-next.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/MIGRATION-v5-to-v6.md +201 -0
- package/README.md +58 -40
- package/lib/cjs/actions/blue/borrow.d.ts +62 -61
- package/lib/cjs/actions/blue/borrow.js +48 -80
- package/lib/cjs/actions/blue/common.d.ts +99 -0
- package/lib/cjs/actions/blue/common.js +318 -0
- package/lib/cjs/actions/blue/refinance.d.ts +72 -112
- package/lib/cjs/actions/blue/refinance.js +97 -199
- package/lib/cjs/actions/blue/repay.d.ts +72 -68
- package/lib/cjs/actions/blue/repay.js +56 -118
- package/lib/cjs/actions/blue/repayWithdrawCollateral.d.ts +85 -90
- package/lib/cjs/actions/blue/repayWithdrawCollateral.js +148 -137
- package/lib/cjs/actions/blue/supply.d.ts +62 -45
- package/lib/cjs/actions/blue/supply.js +94 -70
- package/lib/cjs/actions/blue/supplyCollateral.d.ts +63 -40
- package/lib/cjs/actions/blue/supplyCollateral.js +52 -69
- package/lib/cjs/actions/blue/supplyCollateralBorrow.d.ts +82 -90
- package/lib/cjs/actions/blue/supplyCollateralBorrow.js +133 -120
- package/lib/cjs/actions/blue/withdraw.d.ts +68 -79
- package/lib/cjs/actions/blue/withdraw.js +101 -97
- package/lib/cjs/actions/blue/withdrawCollateral.d.ts +56 -28
- package/lib/cjs/actions/blue/withdrawCollateral.js +45 -50
- package/lib/cjs/actions/index.d.ts +1 -1
- package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +29 -17
- package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.js +60 -19
- package/lib/cjs/actions/requirements/blue/getBlueBundlesV1TokenRequirements.d.ts +80 -0
- package/lib/cjs/actions/requirements/blue/getBlueBundlesV1TokenRequirements.js +207 -0
- package/lib/cjs/actions/requirements/blue/getUnusedPermit2Nonce.d.ts +48 -0
- package/lib/cjs/actions/requirements/blue/getUnusedPermit2Nonce.js +72 -0
- package/lib/cjs/actions/requirements/blue/index.d.ts +2 -0
- package/lib/cjs/actions/requirements/blue/index.js +2 -0
- package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +10 -7
- package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.js +30 -5
- package/lib/cjs/actions/requirements/encode/encodeErc20Approval.d.ts +2 -1
- package/lib/cjs/actions/requirements/encode/encodeErc20Approval.js +7 -2
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +16 -7
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +33 -6
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit2TransferFrom.d.ts +61 -0
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit2TransferFrom.js +123 -0
- package/lib/cjs/actions/requirements/encode/index.d.ts +1 -0
- package/lib/cjs/actions/requirements/encode/index.js +1 -0
- package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts +1 -1
- package/lib/cjs/actions/requirements/getRequirementsApproval.d.ts +5 -4
- package/lib/cjs/actions/requirements/getRequirementsApproval.js +5 -4
- package/lib/cjs/actions/signatures/getTokenRequirementActions.d.ts +1 -0
- package/lib/cjs/actions/signatures/getTokenRequirementActions.js +4 -0
- package/lib/cjs/bundler/actions.d.ts +4 -4
- package/lib/cjs/bundler/actions.js +4 -4
- package/lib/cjs/client/morphoViemExtension.d.ts +2 -1
- package/lib/cjs/client/morphoViemExtension.js +2 -1
- package/lib/cjs/entities/blue/blue.d.ts +806 -374
- package/lib/cjs/entities/blue/blue.js +447 -696
- package/lib/cjs/entities/index.d.ts +1 -0
- package/lib/cjs/helpers/computeVaultV1Reallocations.d.ts +3 -9
- package/lib/cjs/helpers/computeVaultV1Reallocations.js +3 -9
- package/lib/cjs/helpers/validate.d.ts +14 -23
- package/lib/cjs/helpers/validate.js +30 -48
- package/lib/cjs/helpers/validateRequirementSpender.d.ts +2 -1
- package/lib/cjs/helpers/validateRequirementSpender.js +2 -0
- package/lib/cjs/types/action.d.ts +146 -162
- package/lib/cjs/types/action.js +29 -2
- package/lib/cjs/types/client.d.ts +9 -0
- package/lib/cjs/types/error.d.ts +141 -14
- package/lib/cjs/types/error.js +198 -21
- package/lib/cjs/types/sharedLiquidity.d.ts +0 -7
- package/lib/esm/actions/blue/borrow.d.ts +62 -61
- package/lib/esm/actions/blue/borrow.js +48 -80
- package/lib/esm/actions/blue/common.d.ts +99 -0
- package/lib/esm/actions/blue/common.js +306 -0
- package/lib/esm/actions/blue/refinance.d.ts +72 -112
- package/lib/esm/actions/blue/refinance.js +98 -200
- package/lib/esm/actions/blue/repay.d.ts +72 -68
- package/lib/esm/actions/blue/repay.js +56 -118
- package/lib/esm/actions/blue/repayWithdrawCollateral.d.ts +85 -90
- package/lib/esm/actions/blue/repayWithdrawCollateral.js +149 -138
- package/lib/esm/actions/blue/supply.d.ts +62 -45
- package/lib/esm/actions/blue/supply.js +94 -70
- package/lib/esm/actions/blue/supplyCollateral.d.ts +63 -40
- package/lib/esm/actions/blue/supplyCollateral.js +52 -69
- package/lib/esm/actions/blue/supplyCollateralBorrow.d.ts +82 -90
- package/lib/esm/actions/blue/supplyCollateralBorrow.js +134 -121
- package/lib/esm/actions/blue/withdraw.d.ts +68 -79
- package/lib/esm/actions/blue/withdraw.js +100 -96
- package/lib/esm/actions/blue/withdrawCollateral.d.ts +56 -28
- package/lib/esm/actions/blue/withdrawCollateral.js +45 -50
- package/lib/esm/actions/index.d.ts +1 -1
- package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +29 -17
- package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.js +63 -22
- package/lib/esm/actions/requirements/blue/getBlueBundlesV1TokenRequirements.d.ts +80 -0
- package/lib/esm/actions/requirements/blue/getBlueBundlesV1TokenRequirements.js +203 -0
- package/lib/esm/actions/requirements/blue/getUnusedPermit2Nonce.d.ts +48 -0
- package/lib/esm/actions/requirements/blue/getUnusedPermit2Nonce.js +68 -0
- package/lib/esm/actions/requirements/blue/index.d.ts +2 -0
- package/lib/esm/actions/requirements/blue/index.js +2 -0
- package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +10 -7
- package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.js +31 -6
- package/lib/esm/actions/requirements/encode/encodeErc20Approval.d.ts +2 -1
- package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +8 -3
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +16 -7
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +34 -7
- package/lib/esm/actions/requirements/encode/encodeErc20Permit2TransferFrom.d.ts +61 -0
- package/lib/esm/actions/requirements/encode/encodeErc20Permit2TransferFrom.js +119 -0
- package/lib/esm/actions/requirements/encode/index.d.ts +1 -0
- package/lib/esm/actions/requirements/encode/index.js +1 -0
- package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts +1 -1
- package/lib/esm/actions/requirements/getRequirementsApproval.d.ts +5 -4
- package/lib/esm/actions/requirements/getRequirementsApproval.js +5 -4
- package/lib/esm/actions/signatures/getTokenRequirementActions.d.ts +1 -0
- package/lib/esm/actions/signatures/getTokenRequirementActions.js +5 -1
- package/lib/esm/bundler/actions.d.ts +4 -4
- package/lib/esm/bundler/actions.js +4 -4
- package/lib/esm/client/morphoViemExtension.d.ts +2 -1
- package/lib/esm/client/morphoViemExtension.js +2 -1
- package/lib/esm/entities/blue/blue.d.ts +806 -374
- package/lib/esm/entities/blue/blue.js +453 -702
- package/lib/esm/entities/index.d.ts +1 -0
- package/lib/esm/helpers/computeVaultV1Reallocations.d.ts +3 -9
- package/lib/esm/helpers/computeVaultV1Reallocations.js +3 -9
- package/lib/esm/helpers/validate.d.ts +14 -23
- package/lib/esm/helpers/validate.js +30 -48
- package/lib/esm/helpers/validateRequirementSpender.d.ts +2 -1
- package/lib/esm/helpers/validateRequirementSpender.js +2 -0
- package/lib/esm/types/action.d.ts +146 -162
- package/lib/esm/types/action.js +28 -2
- package/lib/esm/types/client.d.ts +9 -0
- package/lib/esm/types/error.d.ts +141 -14
- package/lib/esm/types/error.js +184 -17
- package/lib/esm/types/sharedLiquidity.d.ts +0 -7
- package/package.json +4 -3
- package/lib/cjs/actions/blue/buildAssetFundingActions.d.ts +0 -47
- package/lib/cjs/actions/blue/buildAssetFundingActions.js +0 -63
- package/lib/cjs/actions/blue/buildReallocationActions.d.ts +0 -69
- package/lib/cjs/actions/blue/buildReallocationActions.js +0 -141
- package/lib/cjs/actions/blue/resolveRepayFunding.d.ts +0 -66
- package/lib/cjs/actions/blue/resolveRepayFunding.js +0 -85
- package/lib/esm/actions/blue/buildAssetFundingActions.d.ts +0 -47
- package/lib/esm/actions/blue/buildAssetFundingActions.js +0 -59
- package/lib/esm/actions/blue/buildReallocationActions.d.ts +0 -69
- package/lib/esm/actions/blue/buildReallocationActions.js +0 -135
- package/lib/esm/actions/blue/resolveRepayFunding.d.ts +0 -66
- package/lib/esm/actions/blue/resolveRepayFunding.js +0 -81
|
@@ -101,103 +101,86 @@ export interface VaultV1MigrateToV2Action extends BaseAction<"vaultV1MigrateToV2
|
|
|
101
101
|
recipient: Address;
|
|
102
102
|
}> {
|
|
103
103
|
}
|
|
104
|
+
/** Metadata for a direct BlueBundlesV1 loan-asset supply. */
|
|
104
105
|
export interface BlueSupplyAction extends BaseAction<"blueSupply", {
|
|
105
|
-
market: Hex;
|
|
106
|
-
|
|
107
|
-
onBehalf: Address;
|
|
108
|
-
|
|
109
|
-
|
|
106
|
+
readonly market: Hex;
|
|
107
|
+
readonly assets: bigint;
|
|
108
|
+
readonly onBehalf: Address;
|
|
109
|
+
readonly nativeAmount?: bigint;
|
|
110
|
+
readonly referralFeePct: bigint;
|
|
111
|
+
readonly referralFeeRecipient: Address;
|
|
112
|
+
readonly deadline: bigint;
|
|
110
113
|
}> {
|
|
111
114
|
}
|
|
115
|
+
/** Metadata for a direct BlueBundlesV1 loan-asset withdrawal. */
|
|
112
116
|
export interface BlueWithdrawAction extends BaseAction<"blueWithdraw", {
|
|
113
|
-
market: Hex;
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
/** Native-token fees paid to PublicAllocator V1. */
|
|
119
|
-
reallocationFee: bigint;
|
|
120
|
-
/** Loan-token assets donated as BluePublicAllocator V2 penalties. */
|
|
117
|
+
readonly market: Hex;
|
|
118
|
+
readonly withdrawAssets: bigint;
|
|
119
|
+
readonly withdrawShares: bigint;
|
|
120
|
+
readonly onBehalf: Address;
|
|
121
|
+
readonly reallocations: number;
|
|
121
122
|
readonly reallocationPenaltyAssets: bigint;
|
|
123
|
+
readonly referralFeePct: bigint;
|
|
124
|
+
readonly referralFeeRecipient: Address;
|
|
125
|
+
readonly deadline: bigint;
|
|
122
126
|
}> {
|
|
123
127
|
}
|
|
124
|
-
|
|
125
|
-
market: Hex;
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
market: Hex;
|
|
133
|
-
amount: bigint;
|
|
134
|
-
receiver: Address;
|
|
135
|
-
minSharePrice: bigint;
|
|
136
|
-
/** Native-token fees paid to PublicAllocator V1. */
|
|
137
|
-
reallocationFee: bigint;
|
|
138
|
-
/** Loan-token assets donated as BluePublicAllocator V2 penalties. */
|
|
128
|
+
type BlueSupplyCollateralBorrowActionArgs = {
|
|
129
|
+
readonly market: Hex;
|
|
130
|
+
readonly collateralAssets: bigint;
|
|
131
|
+
readonly borrowAssets: bigint;
|
|
132
|
+
readonly maxLtv: bigint;
|
|
133
|
+
readonly onBehalf: Address;
|
|
134
|
+
readonly nativeAmount?: bigint;
|
|
135
|
+
readonly reallocations: number;
|
|
139
136
|
readonly reallocationPenaltyAssets: bigint;
|
|
140
|
-
|
|
137
|
+
readonly referralFeePct: bigint;
|
|
138
|
+
readonly referralFeeRecipient: Address;
|
|
139
|
+
readonly deadline: bigint;
|
|
140
|
+
};
|
|
141
|
+
/** Metadata for a direct BlueBundlesV1 collateral supply. */
|
|
142
|
+
export interface BlueSupplyCollateralAction extends BaseAction<"blueSupplyCollateral", BlueSupplyCollateralBorrowActionArgs> {
|
|
141
143
|
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
collateralAmount: bigint;
|
|
145
|
-
borrowAmount: bigint;
|
|
146
|
-
minSharePrice: bigint;
|
|
147
|
-
onBehalf: Address;
|
|
148
|
-
receiver: Address;
|
|
149
|
-
nativeAmount?: bigint;
|
|
150
|
-
/** Native-token fees paid to PublicAllocator V1. */
|
|
151
|
-
reallocationFee: bigint;
|
|
152
|
-
/** Loan-token assets donated as BluePublicAllocator V2 penalties. */
|
|
153
|
-
readonly reallocationPenaltyAssets: bigint;
|
|
154
|
-
}> {
|
|
144
|
+
/** Metadata for a direct BlueBundlesV1 borrow. */
|
|
145
|
+
export interface BlueBorrowAction extends BaseAction<"blueBorrow", BlueSupplyCollateralBorrowActionArgs> {
|
|
155
146
|
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
assets: bigint;
|
|
159
|
-
shares: bigint;
|
|
160
|
-
transferAmount: bigint;
|
|
161
|
-
onBehalf: Address;
|
|
162
|
-
receiver: Address;
|
|
163
|
-
maxSharePrice: bigint;
|
|
164
|
-
/** Native token wrapped into wNative to fund the repay. Present when `> 0n`. */
|
|
165
|
-
nativeAmount?: bigint;
|
|
166
|
-
}> {
|
|
147
|
+
/** Metadata for a direct BlueBundlesV1 collateral-supply and/or borrow. */
|
|
148
|
+
export interface BlueSupplyCollateralBorrowAction extends BaseAction<"blueSupplyCollateralBorrow", BlueSupplyCollateralBorrowActionArgs> {
|
|
167
149
|
}
|
|
168
|
-
|
|
169
|
-
market: Hex;
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
150
|
+
type BlueRepayWithdrawCollateralActionArgs = {
|
|
151
|
+
readonly market: Hex;
|
|
152
|
+
readonly repayAssets: bigint;
|
|
153
|
+
readonly repayShares: bigint;
|
|
154
|
+
readonly maxRepayAssets: bigint;
|
|
155
|
+
readonly collateralAssets: bigint;
|
|
156
|
+
readonly maxLtv: bigint;
|
|
157
|
+
readonly onBehalf: Address;
|
|
158
|
+
readonly nativeAmount?: bigint;
|
|
159
|
+
readonly referralFeePct: bigint;
|
|
160
|
+
readonly referralFeeRecipient: Address;
|
|
161
|
+
readonly deadline: bigint;
|
|
162
|
+
};
|
|
163
|
+
/** Metadata for a direct BlueBundlesV1 repayment. */
|
|
164
|
+
export interface BlueRepayAction extends BaseAction<"blueRepay", BlueRepayWithdrawCollateralActionArgs> {
|
|
174
165
|
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
withdrawAmount: bigint;
|
|
181
|
-
maxSharePrice: bigint;
|
|
182
|
-
onBehalf: Address;
|
|
183
|
-
receiver: Address;
|
|
184
|
-
/** Native token wrapped into wNative to fund the repay. Present when `> 0n`. */
|
|
185
|
-
nativeAmount?: bigint;
|
|
186
|
-
}> {
|
|
166
|
+
/** Metadata for a direct BlueBundlesV1 collateral withdrawal. */
|
|
167
|
+
export interface BlueWithdrawCollateralAction extends BaseAction<"blueWithdrawCollateral", BlueRepayWithdrawCollateralActionArgs> {
|
|
168
|
+
}
|
|
169
|
+
/** Metadata for a direct BlueBundlesV1 repay and/or collateral withdrawal. */
|
|
170
|
+
export interface BlueRepayWithdrawCollateralAction extends BaseAction<"blueRepayWithdrawCollateral", BlueRepayWithdrawCollateralActionArgs> {
|
|
187
171
|
}
|
|
172
|
+
/** Metadata for a direct BlueBundlesV1 full borrow-position migration. */
|
|
188
173
|
export interface BlueRefinanceAction extends BaseAction<"blueRefinance", {
|
|
189
174
|
readonly sourceMarket: Hex;
|
|
190
|
-
readonly
|
|
191
|
-
readonly
|
|
192
|
-
readonly
|
|
193
|
-
readonly
|
|
194
|
-
readonly minBorrowSharePrice: bigint;
|
|
195
|
-
readonly maxRepaySharePrice: bigint;
|
|
196
|
-
readonly user: Address;
|
|
197
|
-
/** Native-token fees paid to PublicAllocator V1. */
|
|
198
|
-
readonly reallocationFee: bigint;
|
|
175
|
+
readonly destinationMarket: Hex;
|
|
176
|
+
readonly maxLtv: bigint;
|
|
177
|
+
readonly onBehalf: Address;
|
|
178
|
+
readonly reallocations: number;
|
|
199
179
|
/** Loan-token assets donated as BluePublicAllocator V2 penalties. */
|
|
200
180
|
readonly reallocationPenaltyAssets: bigint;
|
|
181
|
+
readonly referralFeePct: bigint;
|
|
182
|
+
readonly referralFeeRecipient: Address;
|
|
183
|
+
readonly deadline: bigint;
|
|
201
184
|
}> {
|
|
202
185
|
}
|
|
203
186
|
/**
|
|
@@ -207,59 +190,14 @@ export interface BlueRefinanceAction extends BaseAction<"blueRefinance", {
|
|
|
207
190
|
* - `shares`: operate on an exact share count (typical for full position closes,
|
|
208
191
|
* immune to interest accrual between tx construction and execution).
|
|
209
192
|
*
|
|
210
|
-
* Used by
|
|
211
|
-
*
|
|
193
|
+
* Used by BlueBundlesV1 withdrawal; repayment has its own assets-or-shares union because a pure
|
|
194
|
+
* collateral withdrawal has no repay amount.
|
|
212
195
|
*/
|
|
213
196
|
export type AssetsOrSharesArgs = {
|
|
214
|
-
assets: bigint;
|
|
197
|
+
readonly assets: bigint;
|
|
215
198
|
} | {
|
|
216
|
-
shares: bigint;
|
|
217
|
-
};
|
|
218
|
-
/**
|
|
219
|
-
* Repay funding sources for the **entity layer** (`MorphoBlue.repay` /
|
|
220
|
-
* `MorphoBlue.repayWithdrawCollateral`), which computes the loan-token
|
|
221
|
-
* `transferAmount` itself from live market state.
|
|
222
|
-
*
|
|
223
|
-
* - **assets mode** ({@link DepositAmountArgs}): repay an exact asset total of
|
|
224
|
-
* `amount` (ERC-20) + `nativeAmount` (wrapped native). Additive — mirrors `blueSupply`.
|
|
225
|
-
* - **shares mode** (`{ shares }`): repay an exact borrow-share count (full close,
|
|
226
|
-
* immune to interest accrual). `nativeAmount` funds part of the transfer.
|
|
227
|
-
*
|
|
228
|
-
* `nativeAmount` requires the market's loan token to be the chain's wNative.
|
|
229
|
-
*/
|
|
230
|
-
export type RepayAmountArgs = DepositAmountArgs | {
|
|
231
|
-
shares: bigint;
|
|
232
|
-
nativeAmount?: bigint;
|
|
199
|
+
readonly shares: bigint;
|
|
233
200
|
};
|
|
234
|
-
/**
|
|
235
|
-
* Repay funding sources for the **action layer** (`blueRepay` /
|
|
236
|
-
* `blueRepayWithdrawCollateral`) — a flat, pre-resolved shape. The entity layer
|
|
237
|
-
* ({@link RepayAmountArgs}) derives these from live market state; the action does no
|
|
238
|
-
* amount arithmetic. The mode is discriminated on `shares`:
|
|
239
|
-
*
|
|
240
|
-
* - **assets mode** (`shares` unset/`0n`): repays `transferAmount` assets
|
|
241
|
-
* (`= amount + nativeAmount`, additive like `blueSupply`), pulling `amount` ERC-20
|
|
242
|
-
* and wrapping `nativeAmount`. No residual.
|
|
243
|
-
* - **shares mode** (`shares > 0n`): repays an exact borrow-share count (full close),
|
|
244
|
-
* pulling `transferAmount` ERC-20 (already net of native) and wrapping `nativeAmount`;
|
|
245
|
-
* the residual loan token is skimmed back to `receiver`.
|
|
246
|
-
*
|
|
247
|
-
* `nativeAmount` requires the market's loan token to be the chain's wNative.
|
|
248
|
-
*/
|
|
249
|
-
export interface RepayActionAmountArgs {
|
|
250
|
-
/** Assets-mode ERC-20 loan tokens pulled from the payer. Omit (or `0n`) in shares mode. */
|
|
251
|
-
amount?: bigint;
|
|
252
|
-
/** Shares-mode borrow shares to repay (full close). Omit (or `0n`) in assets mode. */
|
|
253
|
-
shares?: bigint;
|
|
254
|
-
/** Native ETH wrapped into wNative to help fund the repay. Loan token must be wNative. */
|
|
255
|
-
nativeAmount?: bigint;
|
|
256
|
-
/**
|
|
257
|
-
* Loan tokens routed into `GeneralAdapter1`. Assets mode: the total repaid
|
|
258
|
-
* (`amount + nativeAmount`). Shares mode: the ERC-20 pulled
|
|
259
|
-
* (`toBorrowAssets(shares) − nativeAmount`).
|
|
260
|
-
*/
|
|
261
|
-
transferAmount: bigint;
|
|
262
|
-
}
|
|
263
201
|
/** Metadata for a Blue authorization prerequisite transaction. */
|
|
264
202
|
export interface BlueAuthorizationAction extends BaseAction<"blueAuthorization", {
|
|
265
203
|
authorized: Address;
|
|
@@ -358,6 +296,7 @@ export interface MidnightCancelOfferAction extends BaseAction<"midnightCancelOff
|
|
|
358
296
|
readonly onBehalf: Address;
|
|
359
297
|
}> {
|
|
360
298
|
}
|
|
299
|
+
/** Metadata discriminators carried by transactions returned by the SDK. */
|
|
361
300
|
export type TransactionAction = ERC20ApprovalAction | VaultV2DepositAction | VaultV2WithdrawAction | VaultV2RedeemAction | VaultV2InKindRedeemAction | VaultV2ForceWithdrawAction | VaultV2ForceRedeemAction | VaultV1DepositAction | VaultV1WithdrawAction | VaultV1RedeemAction | VaultV1InKindRedeemAction | VaultV1MigrateToV2Action | BlueSupplyAction | BlueWithdrawAction | BlueSupplyCollateralAction | BlueBorrowAction | BlueSupplyCollateralBorrowAction | BlueRepayAction | BlueWithdrawCollateralAction | BlueRepayWithdrawCollateralAction | BlueRefinanceAction | BlueAuthorizationAction | MidnightAuthorizationAction | SetterRatifierRatifyRootAction | MidnightTakeLendAction | MidnightTakeBorrowAction | MidnightSupplyCollateralTakeBorrowAction | MidnightSupplyCollateralAction | MempoolSubmitOffersAction | MidnightRedeemAction | MidnightRepayWithdrawCollateralAction | MidnightCancelOfferAction;
|
|
362
301
|
export interface Transaction<TAction extends BaseAction = TransactionAction> {
|
|
363
302
|
readonly to: Address;
|
|
@@ -398,22 +337,22 @@ export interface Permit2Args {
|
|
|
398
337
|
}
|
|
399
338
|
/**
|
|
400
339
|
* Signed Morpho Blue authorization payload produced when an integrator opts into offchain
|
|
401
|
-
* signatures (`supportSignature: true`).
|
|
402
|
-
*
|
|
340
|
+
* signatures (`supportSignature: true`). Bundler3 consumes it through `setAuthorizationWithSig`;
|
|
341
|
+
* direct BlueBundlesV1 writes encode it into their signed-authorization struct.
|
|
403
342
|
*/
|
|
404
343
|
export interface AuthorizationSignatureArgs {
|
|
405
344
|
/** Account granting the authorization (the position owner). */
|
|
406
|
-
owner: Address;
|
|
407
|
-
/** Account being authorized to operate on Morpho on the owner's behalf
|
|
408
|
-
authorized: Address;
|
|
345
|
+
readonly owner: Address;
|
|
346
|
+
/** Account being authorized to operate on Morpho on the owner's behalf. */
|
|
347
|
+
readonly authorized: Address;
|
|
409
348
|
/** Whether the authorization is granted (`true`) or revoked (`false`). */
|
|
410
|
-
isAuthorized: boolean;
|
|
349
|
+
readonly isAuthorized: boolean;
|
|
411
350
|
/** Morpho authorization nonce consumed by the signature. */
|
|
412
|
-
nonce: bigint;
|
|
351
|
+
readonly nonce: bigint;
|
|
413
352
|
/** Signature deadline timestamp in seconds. */
|
|
414
|
-
deadline: bigint;
|
|
353
|
+
readonly deadline: bigint;
|
|
415
354
|
/** EIP-712 signature over the Morpho `Authorization` typed data. */
|
|
416
|
-
signature: Hex;
|
|
355
|
+
readonly signature: Hex;
|
|
417
356
|
}
|
|
418
357
|
/** Signed and encoded Ecrecover offer-root payload used by Midnight maker flows. */
|
|
419
358
|
export interface MidnightOfferRootSignatureArgs {
|
|
@@ -435,9 +374,16 @@ export interface Permit2Action extends BaseAction<"permit2", {
|
|
|
435
374
|
expiration: bigint;
|
|
436
375
|
}> {
|
|
437
376
|
}
|
|
377
|
+
/** Signable Permit2 SignatureTransfer requirement for a direct BlueBundlesV1 pull. */
|
|
378
|
+
export interface Permit2TransferFromAction extends BaseAction<"permit2TransferFrom", {
|
|
379
|
+
readonly spender: Address;
|
|
380
|
+
readonly amount: bigint;
|
|
381
|
+
readonly deadline: bigint;
|
|
382
|
+
}> {
|
|
383
|
+
}
|
|
438
384
|
/**
|
|
439
|
-
* Signable Morpho authorization requirement.
|
|
440
|
-
*
|
|
385
|
+
* Signable Morpho authorization requirement. Its `authorized` operator is route-specific:
|
|
386
|
+
* GeneralAdapter1 for Bundler3 flows or BlueBundlesV1 for direct Blue writes.
|
|
441
387
|
*/
|
|
442
388
|
export interface AuthorizationAction extends BaseAction<"authorization", {
|
|
443
389
|
authorized: Address;
|
|
@@ -453,18 +399,30 @@ export interface MidnightOfferRootSignatureAction extends BaseAction<"midnightOf
|
|
|
453
399
|
}> {
|
|
454
400
|
}
|
|
455
401
|
/** Action metadata supported by signature requirements. */
|
|
456
|
-
export type SignatureRequirementAction = PermitAction | Permit2Action | AuthorizationAction | MidnightOfferRootSignatureAction;
|
|
402
|
+
export type SignatureRequirementAction = PermitAction | Permit2Action | Permit2TransferFromAction | AuthorizationAction | MidnightOfferRootSignatureAction;
|
|
457
403
|
/** Argument payloads returned by signature requirements. */
|
|
458
404
|
export type RequirementSignatureArgs = PermitArgs | Permit2Args | AuthorizationSignatureArgs | MidnightOfferRootSignatureArgs;
|
|
459
|
-
/** A signed ERC-2612 permit
|
|
460
|
-
export interface
|
|
461
|
-
args: PermitArgs
|
|
462
|
-
action: PermitAction
|
|
463
|
-
}
|
|
464
|
-
/** A signed
|
|
405
|
+
/** A signed ERC-2612 permit requirement. */
|
|
406
|
+
export interface Erc2612RequirementSignature {
|
|
407
|
+
readonly args: Readonly<PermitArgs>;
|
|
408
|
+
readonly action: PermitAction;
|
|
409
|
+
}
|
|
410
|
+
/** A signed Permit2 AllowanceTransfer requirement used by Bundler3. */
|
|
411
|
+
export interface Permit2AllowanceRequirementSignature {
|
|
412
|
+
readonly args: Readonly<Permit2Args>;
|
|
413
|
+
readonly action: Permit2Action;
|
|
414
|
+
}
|
|
415
|
+
/** A signed ERC-2612 permit or Permit2 AllowanceTransfer requirement. */
|
|
416
|
+
export type PermitRequirementSignature = Erc2612RequirementSignature | Permit2AllowanceRequirementSignature;
|
|
417
|
+
/** A signed Permit2 SignatureTransfer requirement used by BlueBundlesV1. */
|
|
418
|
+
export interface Permit2TransferFromRequirementSignature {
|
|
419
|
+
readonly args: Readonly<PermitArgs>;
|
|
420
|
+
readonly action: Permit2TransferFromAction;
|
|
421
|
+
}
|
|
422
|
+
/** A signed Morpho authorization consumed by Bundler3 or a direct BlueBundlesV1 call. */
|
|
465
423
|
export interface AuthorizationRequirementSignature {
|
|
466
|
-
args: AuthorizationSignatureArgs;
|
|
467
|
-
action: AuthorizationAction;
|
|
424
|
+
readonly args: AuthorizationSignatureArgs;
|
|
425
|
+
readonly action: AuthorizationAction;
|
|
468
426
|
}
|
|
469
427
|
/** A signed Midnight Ecrecover offer-root requirement. */
|
|
470
428
|
export interface MidnightOfferRootSignature {
|
|
@@ -473,13 +431,14 @@ export interface MidnightOfferRootSignature {
|
|
|
473
431
|
}
|
|
474
432
|
/**
|
|
475
433
|
* The deep-frozen output of `Requirement.sign()`. Discriminated on `action.type`:
|
|
476
|
-
* `"permit"` / `"permit2"` carry
|
|
477
|
-
*
|
|
434
|
+
* `"permit"` / `"permit2"` carry token-approval args, `"permit2TransferFrom"` carries a
|
|
435
|
+
* BlueBundlesV1 SignatureTransfer, `"authorization"` carries the signed Morpho authorization,
|
|
436
|
+
* and Midnight adds `"midnightOfferRootSignature"`.
|
|
478
437
|
*/
|
|
479
438
|
export type RequirementSignature<TAction extends SignatureRequirementAction | undefined = undefined, TArgs extends RequirementSignatureArgs | undefined = undefined> = TAction extends SignatureRequirementAction ? TArgs extends RequirementSignatureArgs ? {
|
|
480
439
|
args: TArgs;
|
|
481
440
|
action: TAction;
|
|
482
|
-
} : never : PermitRequirementSignature | AuthorizationRequirementSignature | MidnightOfferRootSignature;
|
|
441
|
+
} : never : PermitRequirementSignature | Permit2TransferFromRequirementSignature | AuthorizationRequirementSignature | MidnightOfferRootSignature;
|
|
483
442
|
type RequirementResult<TSignatureOrAction extends RequirementSignature | SignatureRequirementAction, TArgs extends RequirementSignatureArgs | undefined> = TSignatureOrAction extends SignatureRequirementAction ? RequirementSignature<TSignatureOrAction, Extract<TArgs, RequirementSignatureArgs>> : Extract<TSignatureOrAction, RequirementSignature>;
|
|
484
443
|
/**
|
|
485
444
|
* A signable approval / authorization requirement. `sign()` returns the matching
|
|
@@ -496,14 +455,18 @@ export interface Requirement<TSignatureOrAction extends RequirementSignature | S
|
|
|
496
455
|
}
|
|
497
456
|
/** Bundler3 token signature requirement. */
|
|
498
457
|
export type Bundler3TokenSignatureRequirement = Requirement<PermitRequirementSignature>;
|
|
458
|
+
/** BlueBundlesV1 ERC-2612 or Permit2 SignatureTransfer requirement. */
|
|
459
|
+
export type BlueBundlesV1TokenSignatureRequirement = Requirement<BlueBundlesV1TokenRequirementSignature>;
|
|
499
460
|
/** Midnight Ecrecover offer-root signature requirement. */
|
|
500
461
|
export type MidnightOfferRootRequirement = Requirement<MidnightOfferRootSignatureAction, MidnightOfferRootSignatureArgs>;
|
|
501
|
-
/**
|
|
502
|
-
export type TokenSignatureRequirement = Bundler3TokenSignatureRequirement;
|
|
462
|
+
/** Any token signature requirement supported by an SDK transaction route. */
|
|
463
|
+
export type TokenSignatureRequirement = Bundler3TokenSignatureRequirement | BlueBundlesV1TokenSignatureRequirement;
|
|
503
464
|
/** Bundler3 token signature result. */
|
|
504
465
|
export type Bundler3TokenRequirementSignature = PermitRequirementSignature;
|
|
505
|
-
/**
|
|
506
|
-
export type
|
|
466
|
+
/** BlueBundlesV1 token signature result. */
|
|
467
|
+
export type BlueBundlesV1TokenRequirementSignature = Erc2612RequirementSignature | Permit2TransferFromRequirementSignature;
|
|
468
|
+
/** Any token signature result supported by an SDK transaction route. */
|
|
469
|
+
export type TokenRequirementSignature = Bundler3TokenRequirementSignature | BlueBundlesV1TokenRequirementSignature;
|
|
507
470
|
/** Any signature result returned by an action-output signature requirement. */
|
|
508
471
|
export type AnyRequirementSignature = TokenRequirementSignature | AuthorizationRequirementSignature | MidnightOfferRootSignature;
|
|
509
472
|
/** Any signature requirement returned by an entity action output. */
|
|
@@ -541,6 +504,23 @@ export declare function isRequirementSignature(requirement: ActionRequirement |
|
|
|
541
504
|
* @returns `true` when `signature.action.type` is `"permit"` or `"permit2"`.
|
|
542
505
|
*/
|
|
543
506
|
export declare function isPermitSignature(signature: RequirementSignature): signature is PermitRequirementSignature;
|
|
507
|
+
/**
|
|
508
|
+
* Narrows a {@link RequirementSignature} to a Permit2 SignatureTransfer result.
|
|
509
|
+
*
|
|
510
|
+
* @param signature - The signed requirement to test.
|
|
511
|
+
* @returns `true` when `signature.action.type` is `"permit2TransferFrom"`.
|
|
512
|
+
* @example
|
|
513
|
+
* ```ts
|
|
514
|
+
* import {
|
|
515
|
+
* isPermit2TransferFromSignature,
|
|
516
|
+
* type RequirementSignature,
|
|
517
|
+
* } from "@morpho-org/morpho-sdk";
|
|
518
|
+
*
|
|
519
|
+
* const getPermit2Nonce = (signature: RequirementSignature): bigint | undefined =>
|
|
520
|
+
* isPermit2TransferFromSignature(signature) ? signature.args.nonce : undefined;
|
|
521
|
+
* ```
|
|
522
|
+
*/
|
|
523
|
+
export declare function isPermit2TransferFromSignature(signature: RequirementSignature): signature is Permit2TransferFromRequirementSignature;
|
|
544
524
|
/**
|
|
545
525
|
* Narrows a {@link RequirementSignature} to a signed Morpho authorization.
|
|
546
526
|
*
|
|
@@ -557,12 +537,14 @@ export declare function isAuthorizationSignature(signature: RequirementSignature
|
|
|
557
537
|
export declare function isMidnightOfferRootSignature(signature: RequirementSignature): signature is MidnightOfferRootSignature;
|
|
558
538
|
/** The typed requirement-signature slots a transaction builder consumes, split from a `buildTx` array. */
|
|
559
539
|
export interface SelectedRequirementSignatures {
|
|
560
|
-
/** The single
|
|
561
|
-
permit?: PermitRequirementSignature;
|
|
540
|
+
/** The single ERC-2612 or Permit2 AllowanceTransfer signature, when present. */
|
|
541
|
+
readonly permit?: PermitRequirementSignature;
|
|
542
|
+
/** The single Permit2 SignatureTransfer signature, when present. */
|
|
543
|
+
readonly permit2TransferFrom?: Permit2TransferFromRequirementSignature;
|
|
562
544
|
/** The single Morpho authorization signature, when present. */
|
|
563
|
-
authorization?: AuthorizationRequirementSignature;
|
|
545
|
+
readonly authorization?: AuthorizationRequirementSignature;
|
|
564
546
|
/** The single Midnight offer-root signature, when present. */
|
|
565
|
-
midnightOfferRoot?: MidnightOfferRootSignature;
|
|
547
|
+
readonly midnightOfferRoot?: MidnightOfferRootSignature;
|
|
566
548
|
}
|
|
567
549
|
/**
|
|
568
550
|
* Splits a `buildTx` signature array into its typed requirement-signature slots, rejecting
|
|
@@ -575,10 +557,11 @@ export interface SelectedRequirementSignatures {
|
|
|
575
557
|
*
|
|
576
558
|
* @param signatures - The signatures passed to `buildTx`.
|
|
577
559
|
* @param accepts - Which signature kinds this operation consumes.
|
|
578
|
-
* @param accepts.permit - Whether
|
|
560
|
+
* @param accepts.permit - Whether an ERC-2612 or Permit2 AllowanceTransfer signature is consumed.
|
|
561
|
+
* @param accepts.permit2TransferFrom - Whether a Permit2 SignatureTransfer is consumed.
|
|
579
562
|
* @param accepts.authorization - Whether a Morpho authorization signature is consumed.
|
|
580
563
|
* @param accepts.midnightOfferRoot - Whether a Midnight offer-root signature is consumed.
|
|
581
|
-
* @returns The
|
|
564
|
+
* @returns The accepted signature in each typed slot, when present.
|
|
582
565
|
* @throws {AmbiguousRequirementSignaturesError} when more than one signature of an accepted kind is present.
|
|
583
566
|
* @throws {UnexpectedRequirementSignatureError} when a signature of a kind the operation does not consume is present.
|
|
584
567
|
* @example
|
|
@@ -593,6 +576,7 @@ export interface SelectedRequirementSignatures {
|
|
|
593
576
|
*/
|
|
594
577
|
export declare function selectRequirementSignatures(signatures: readonly RequirementSignature[] | undefined, accepts: {
|
|
595
578
|
permit?: boolean;
|
|
579
|
+
permit2TransferFrom?: boolean;
|
|
596
580
|
authorization?: boolean;
|
|
597
581
|
midnightOfferRoot?: boolean;
|
|
598
582
|
}): SelectedRequirementSignatures;
|
package/lib/cjs/types/action.js
CHANGED
|
@@ -4,6 +4,7 @@ exports.isRequirementApproval = isRequirementApproval;
|
|
|
4
4
|
exports.isRequirementBlueAuthorization = isRequirementBlueAuthorization;
|
|
5
5
|
exports.isRequirementSignature = isRequirementSignature;
|
|
6
6
|
exports.isPermitSignature = isPermitSignature;
|
|
7
|
+
exports.isPermit2TransferFromSignature = isPermit2TransferFromSignature;
|
|
7
8
|
exports.isAuthorizationSignature = isAuthorizationSignature;
|
|
8
9
|
exports.isMidnightOfferRootSignature = isMidnightOfferRootSignature;
|
|
9
10
|
exports.selectRequirementSignatures = selectRequirementSignatures;
|
|
@@ -49,6 +50,25 @@ function isRequirementSignature(requirement) {
|
|
|
49
50
|
function isPermitSignature(signature) {
|
|
50
51
|
return (signature.action.type === "permit" || signature.action.type === "permit2");
|
|
51
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* Narrows a {@link RequirementSignature} to a Permit2 SignatureTransfer result.
|
|
55
|
+
*
|
|
56
|
+
* @param signature - The signed requirement to test.
|
|
57
|
+
* @returns `true` when `signature.action.type` is `"permit2TransferFrom"`.
|
|
58
|
+
* @example
|
|
59
|
+
* ```ts
|
|
60
|
+
* import {
|
|
61
|
+
* isPermit2TransferFromSignature,
|
|
62
|
+
* type RequirementSignature,
|
|
63
|
+
* } from "@morpho-org/morpho-sdk";
|
|
64
|
+
*
|
|
65
|
+
* const getPermit2Nonce = (signature: RequirementSignature): bigint | undefined =>
|
|
66
|
+
* isPermit2TransferFromSignature(signature) ? signature.args.nonce : undefined;
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
function isPermit2TransferFromSignature(signature) {
|
|
70
|
+
return signature.action.type === "permit2TransferFrom";
|
|
71
|
+
}
|
|
52
72
|
/**
|
|
53
73
|
* Narrows a {@link RequirementSignature} to a signed Morpho authorization.
|
|
54
74
|
*
|
|
@@ -78,10 +98,11 @@ function isMidnightOfferRootSignature(signature) {
|
|
|
78
98
|
*
|
|
79
99
|
* @param signatures - The signatures passed to `buildTx`.
|
|
80
100
|
* @param accepts - Which signature kinds this operation consumes.
|
|
81
|
-
* @param accepts.permit - Whether
|
|
101
|
+
* @param accepts.permit - Whether an ERC-2612 or Permit2 AllowanceTransfer signature is consumed.
|
|
102
|
+
* @param accepts.permit2TransferFrom - Whether a Permit2 SignatureTransfer is consumed.
|
|
82
103
|
* @param accepts.authorization - Whether a Morpho authorization signature is consumed.
|
|
83
104
|
* @param accepts.midnightOfferRoot - Whether a Midnight offer-root signature is consumed.
|
|
84
|
-
* @returns The
|
|
105
|
+
* @returns The accepted signature in each typed slot, when present.
|
|
85
106
|
* @throws {AmbiguousRequirementSignaturesError} when more than one signature of an accepted kind is present.
|
|
86
107
|
* @throws {UnexpectedRequirementSignatureError} when a signature of a kind the operation does not consume is present.
|
|
87
108
|
* @example
|
|
@@ -98,22 +119,28 @@ function selectRequirementSignatures(signatures, accepts) {
|
|
|
98
119
|
if (signatures == null)
|
|
99
120
|
return {};
|
|
100
121
|
const permits = signatures.filter(isPermitSignature);
|
|
122
|
+
const permit2Transfers = signatures.filter(isPermit2TransferFromSignature);
|
|
101
123
|
const authorizations = signatures.filter(isAuthorizationSignature);
|
|
102
124
|
const midnightOfferRoots = signatures.filter(isMidnightOfferRootSignature);
|
|
103
125
|
if (!accepts.permit && permits.length > 0)
|
|
104
126
|
throw new error_js_1.UnexpectedRequirementSignatureError("permit");
|
|
127
|
+
if (!accepts.permit2TransferFrom && permit2Transfers.length > 0)
|
|
128
|
+
throw new error_js_1.UnexpectedRequirementSignatureError("permit2TransferFrom");
|
|
105
129
|
if (!accepts.authorization && authorizations.length > 0)
|
|
106
130
|
throw new error_js_1.UnexpectedRequirementSignatureError("authorization");
|
|
107
131
|
if (!accepts.midnightOfferRoot && midnightOfferRoots.length > 0)
|
|
108
132
|
throw new error_js_1.UnexpectedRequirementSignatureError("midnightOfferRootSignature");
|
|
109
133
|
if (permits.length > 1)
|
|
110
134
|
throw new error_js_1.AmbiguousRequirementSignaturesError("permit", permits.length);
|
|
135
|
+
if (permit2Transfers.length > 1)
|
|
136
|
+
throw new error_js_1.AmbiguousRequirementSignaturesError("permit2TransferFrom", permit2Transfers.length);
|
|
111
137
|
if (authorizations.length > 1)
|
|
112
138
|
throw new error_js_1.AmbiguousRequirementSignaturesError("authorization", authorizations.length);
|
|
113
139
|
if (midnightOfferRoots.length > 1)
|
|
114
140
|
throw new error_js_1.AmbiguousRequirementSignaturesError("midnightOfferRootSignature", midnightOfferRoots.length);
|
|
115
141
|
return {
|
|
116
142
|
permit: permits[0],
|
|
143
|
+
permit2TransferFrom: permit2Transfers[0],
|
|
117
144
|
authorization: authorizations[0],
|
|
118
145
|
midnightOfferRoot: midnightOfferRoots[0],
|
|
119
146
|
};
|
|
@@ -8,14 +8,23 @@ import type { Metadata } from "./index.js";
|
|
|
8
8
|
* resolved options bag, and the four entity-factory methods the SDK exposes.
|
|
9
9
|
*/
|
|
10
10
|
export interface MorphoClientType {
|
|
11
|
+
/** Viem client shared by every entity factory and onchain read. */
|
|
11
12
|
readonly viemClient: Client;
|
|
13
|
+
/** Resolved immutable SDK options shared by every entity. */
|
|
12
14
|
readonly options: {
|
|
15
|
+
/** Whether entity prerequisites may be returned as signable EIP-712 requirements. */
|
|
13
16
|
readonly supportSignature: boolean;
|
|
17
|
+
/** Whether supported entity fetchers may use deployless reads. */
|
|
14
18
|
readonly supportDeployless?: boolean;
|
|
19
|
+
/** Optional analytics metadata appended to built transactions. */
|
|
15
20
|
readonly metadata?: Metadata;
|
|
16
21
|
};
|
|
22
|
+
/** Creates a Vault V1 entity bound to `vault` on `chainId`. */
|
|
17
23
|
vaultV1: (vault: Address, chainId: number) => VaultV1Actions;
|
|
24
|
+
/** Creates a Vault V2 entity bound to `vault` on `chainId`. */
|
|
18
25
|
vaultV2: (vault: Address, chainId: number) => VaultV2Actions;
|
|
26
|
+
/** Creates a Morpho Blue market entity whose high-level writes use BlueBundlesV1. */
|
|
19
27
|
blue: (marketParams: MarketParams, chainId: number) => BlueActions;
|
|
28
|
+
/** Creates a Midnight entity bound to `chainId`. */
|
|
20
29
|
midnight: (chainId: number) => MidnightActions;
|
|
21
30
|
}
|