@morpho-org/morpho-sdk 6.0.0-next.0 → 6.0.0-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/MIGRATION-v5-to-v6.md +206 -3
- package/README.md +81 -41
- package/lib/cjs/abis.d.ts +210 -0
- package/lib/cjs/abis.js +142 -2
- package/lib/cjs/actions/blue/borrow.d.ts +1 -1
- package/lib/cjs/actions/blue/borrow.js +1 -1
- package/lib/cjs/actions/blue/common.d.ts +6 -19
- package/lib/cjs/actions/blue/common.js +25 -138
- package/lib/cjs/actions/blue/refinance.d.ts +1 -1
- package/lib/cjs/actions/blue/refinance.js +1 -1
- package/lib/cjs/actions/blue/repay.d.ts +3 -3
- package/lib/cjs/actions/blue/repay.js +1 -1
- package/lib/cjs/actions/blue/repayWithdrawCollateral.d.ts +3 -3
- package/lib/cjs/actions/blue/repayWithdrawCollateral.js +1 -1
- package/lib/cjs/actions/blue/supply.d.ts +3 -3
- package/lib/cjs/actions/blue/supply.js +1 -1
- package/lib/cjs/actions/blue/supplyCollateral.d.ts +3 -3
- package/lib/cjs/actions/blue/supplyCollateral.js +1 -1
- package/lib/cjs/actions/blue/supplyCollateralBorrow.d.ts +3 -3
- package/lib/cjs/actions/blue/supplyCollateralBorrow.js +1 -1
- package/lib/cjs/actions/blue/withdraw.d.ts +1 -1
- package/lib/cjs/actions/blue/withdraw.js +1 -1
- package/lib/cjs/actions/blue/withdrawCollateral.d.ts +1 -1
- package/lib/cjs/actions/blue/withdrawCollateral.js +1 -1
- package/lib/cjs/actions/bundles/common.d.ts +200 -0
- package/lib/cjs/actions/bundles/common.js +469 -0
- package/lib/cjs/actions/bundles/index.d.ts +3 -0
- package/lib/cjs/actions/bundles/index.js +23 -0
- package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.d.ts +76 -0
- package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.js +125 -0
- package/lib/cjs/actions/index.d.ts +1 -0
- package/lib/cjs/actions/index.js +1 -0
- package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.d.ts +2 -2
- package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.js +2 -2
- package/lib/cjs/actions/midnight/takeBorrow.d.ts +2 -2
- package/lib/cjs/actions/midnight/takeBorrow.js +2 -2
- package/lib/cjs/actions/midnight/takeLend.d.ts +2 -2
- package/lib/cjs/actions/midnight/takeLend.js +2 -2
- package/lib/cjs/actions/requirements/blue/getUnusedPermit2Nonce.d.ts +1 -1
- package/lib/cjs/actions/requirements/blue/getUnusedPermit2Nonce.js +1 -1
- package/lib/cjs/actions/requirements/blue/index.d.ts +0 -1
- package/lib/cjs/actions/requirements/blue/index.js +0 -1
- package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.js +1 -1
- package/lib/cjs/actions/requirements/encode/encodeErc20Approval.d.ts +1 -1
- package/lib/cjs/actions/requirements/encode/encodeErc20Approval.js +2 -1
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +3 -3
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +10 -4
- package/lib/{esm/actions/requirements/encode/encodeErc20Permit2TransferFrom.d.ts → cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts} +12 -12
- package/lib/cjs/actions/requirements/encode/{encodeErc20Permit2TransferFrom.js → encodeErc20Permit2SignatureTransfer.js} +13 -13
- package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.d.ts +4 -4
- package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.js +6 -5
- package/lib/cjs/actions/requirements/encode/index.d.ts +1 -1
- package/lib/cjs/actions/requirements/encode/index.js +1 -1
- package/lib/cjs/actions/requirements/getRequirementsApproval.d.ts +4 -3
- package/lib/cjs/actions/requirements/getRequirementsApproval.js +4 -3
- package/lib/cjs/actions/signatures/getTokenRequirementActions.js +2 -2
- package/lib/cjs/actions/signatures/getVaultExitBundlesV1PermitStruct.d.ts +22 -30
- package/lib/cjs/actions/signatures/getVaultExitBundlesV1PermitStruct.js +18 -66
- package/lib/cjs/actions/vaultV1/deposit.d.ts +73 -57
- package/lib/cjs/actions/vaultV1/deposit.js +110 -109
- package/lib/cjs/actions/vaultV1/migrateToV2.d.ts +43 -66
- package/lib/cjs/actions/vaultV1/migrateToV2.js +91 -104
- package/lib/cjs/actions/vaultV1/redeem.d.ts +30 -23
- package/lib/cjs/actions/vaultV1/redeem.js +56 -33
- package/lib/cjs/actions/vaultV1/withdraw.d.ts +58 -24
- package/lib/cjs/actions/vaultV1/withdraw.js +86 -34
- package/lib/cjs/actions/vaultV2/deposit.d.ts +74 -57
- package/lib/cjs/actions/vaultV2/deposit.js +111 -109
- package/lib/cjs/actions/vaultV2/redeem.d.ts +30 -24
- package/lib/cjs/actions/vaultV2/redeem.js +56 -34
- package/lib/cjs/actions/vaultV2/withdraw.d.ts +58 -25
- package/lib/cjs/actions/vaultV2/withdraw.js +86 -35
- package/lib/cjs/entities/blue/blue.d.ts +19 -19
- package/lib/cjs/entities/blue/blue.js +3 -1
- package/lib/cjs/entities/index.d.ts +1 -0
- package/lib/cjs/entities/index.js +15 -0
- package/lib/cjs/entities/midnight/midnight.d.ts +2 -2
- package/lib/cjs/{actions/requirements/blue/getBlueBundlesV1TokenRequirements.d.ts → entities/requirements/getBundlesTokenRequirements.d.ts} +21 -14
- package/lib/cjs/{actions/requirements/blue/getBlueBundlesV1TokenRequirements.js → entities/requirements/getBundlesTokenRequirements.js} +61 -65
- package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.d.ts +28 -0
- package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.js +74 -0
- package/lib/cjs/entities/requirements/index.d.ts +1 -0
- package/lib/cjs/entities/requirements/index.js +17 -0
- package/lib/cjs/entities/vaultV1/vaultV1.d.ts +348 -98
- package/lib/cjs/entities/vaultV1/vaultV1.js +322 -120
- package/lib/cjs/entities/vaultV2/vaultV2.d.ts +221 -68
- package/lib/cjs/entities/vaultV2/vaultV2.js +219 -77
- package/lib/cjs/helpers/index.d.ts +2 -1
- package/lib/cjs/helpers/index.js +5 -1
- package/lib/cjs/helpers/referralFee.d.ts +21 -0
- package/lib/cjs/helpers/referralFee.js +35 -0
- package/lib/cjs/helpers/slippage.d.ts +90 -1
- package/lib/cjs/helpers/slippage.js +123 -0
- package/lib/cjs/helpers/validate.d.ts +2 -0
- package/lib/cjs/helpers/validate.js +12 -1
- package/lib/cjs/helpers/validateRequirementSpender.d.ts +1 -1
- package/lib/cjs/helpers/validateRequirementSpender.js +1 -0
- package/lib/cjs/index.d.ts +1 -0
- package/lib/cjs/index.js +1 -0
- package/lib/cjs/types/action.d.ts +179 -70
- package/lib/cjs/types/action.js +12 -12
- package/lib/cjs/types/error.d.ts +62 -14
- package/lib/cjs/types/error.js +88 -22
- package/lib/esm/abis.d.ts +210 -0
- package/lib/esm/abis.js +140 -0
- package/lib/esm/actions/blue/borrow.d.ts +1 -1
- package/lib/esm/actions/blue/borrow.js +1 -1
- package/lib/esm/actions/blue/common.d.ts +6 -19
- package/lib/esm/actions/blue/common.js +27 -140
- package/lib/esm/actions/blue/refinance.d.ts +1 -1
- package/lib/esm/actions/blue/refinance.js +1 -1
- package/lib/esm/actions/blue/repay.d.ts +3 -3
- package/lib/esm/actions/blue/repay.js +1 -1
- package/lib/esm/actions/blue/repayWithdrawCollateral.d.ts +3 -3
- package/lib/esm/actions/blue/repayWithdrawCollateral.js +1 -1
- package/lib/esm/actions/blue/supply.d.ts +3 -3
- package/lib/esm/actions/blue/supply.js +1 -1
- package/lib/esm/actions/blue/supplyCollateral.d.ts +3 -3
- package/lib/esm/actions/blue/supplyCollateral.js +1 -1
- package/lib/esm/actions/blue/supplyCollateralBorrow.d.ts +3 -3
- package/lib/esm/actions/blue/supplyCollateralBorrow.js +1 -1
- package/lib/esm/actions/blue/withdraw.d.ts +1 -1
- package/lib/esm/actions/blue/withdraw.js +1 -1
- package/lib/esm/actions/blue/withdrawCollateral.d.ts +1 -1
- package/lib/esm/actions/blue/withdrawCollateral.js +1 -1
- package/lib/esm/actions/bundles/common.d.ts +200 -0
- package/lib/esm/actions/bundles/common.js +457 -0
- package/lib/esm/actions/bundles/index.d.ts +3 -0
- package/lib/esm/actions/bundles/index.js +2 -0
- package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.d.ts +76 -0
- package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.js +121 -0
- package/lib/esm/actions/index.d.ts +1 -0
- package/lib/esm/actions/index.js +1 -0
- package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.d.ts +2 -2
- package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.js +2 -2
- package/lib/esm/actions/midnight/takeBorrow.d.ts +2 -2
- package/lib/esm/actions/midnight/takeBorrow.js +2 -2
- package/lib/esm/actions/midnight/takeLend.d.ts +2 -2
- package/lib/esm/actions/midnight/takeLend.js +2 -2
- package/lib/esm/actions/requirements/blue/getUnusedPermit2Nonce.d.ts +1 -1
- package/lib/esm/actions/requirements/blue/getUnusedPermit2Nonce.js +1 -1
- package/lib/esm/actions/requirements/blue/index.d.ts +0 -1
- package/lib/esm/actions/requirements/blue/index.js +0 -1
- package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.js +1 -1
- package/lib/esm/actions/requirements/encode/encodeErc20Approval.d.ts +1 -1
- package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +2 -1
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +3 -3
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +10 -4
- package/lib/{cjs/actions/requirements/encode/encodeErc20Permit2TransferFrom.d.ts → esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts} +12 -12
- package/lib/esm/actions/requirements/encode/{encodeErc20Permit2TransferFrom.js → encodeErc20Permit2SignatureTransfer.js} +11 -11
- package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.d.ts +4 -4
- package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.js +6 -5
- package/lib/esm/actions/requirements/encode/index.d.ts +1 -1
- package/lib/esm/actions/requirements/encode/index.js +1 -1
- package/lib/esm/actions/requirements/getRequirementsApproval.d.ts +4 -3
- package/lib/esm/actions/requirements/getRequirementsApproval.js +4 -3
- package/lib/esm/actions/signatures/getTokenRequirementActions.js +3 -3
- package/lib/esm/actions/signatures/getVaultExitBundlesV1PermitStruct.d.ts +22 -30
- package/lib/esm/actions/signatures/getVaultExitBundlesV1PermitStruct.js +19 -67
- package/lib/esm/actions/vaultV1/deposit.d.ts +73 -57
- package/lib/esm/actions/vaultV1/deposit.js +112 -111
- package/lib/esm/actions/vaultV1/migrateToV2.d.ts +43 -66
- package/lib/esm/actions/vaultV1/migrateToV2.js +93 -106
- package/lib/esm/actions/vaultV1/redeem.d.ts +30 -23
- package/lib/esm/actions/vaultV1/redeem.js +56 -33
- package/lib/esm/actions/vaultV1/withdraw.d.ts +58 -24
- package/lib/esm/actions/vaultV1/withdraw.js +86 -34
- package/lib/esm/actions/vaultV2/deposit.d.ts +74 -57
- package/lib/esm/actions/vaultV2/deposit.js +113 -111
- package/lib/esm/actions/vaultV2/redeem.d.ts +30 -24
- package/lib/esm/actions/vaultV2/redeem.js +56 -34
- package/lib/esm/actions/vaultV2/withdraw.d.ts +58 -25
- package/lib/esm/actions/vaultV2/withdraw.js +86 -35
- package/lib/esm/entities/blue/blue.d.ts +19 -19
- package/lib/esm/entities/blue/blue.js +4 -2
- package/lib/esm/entities/index.d.ts +1 -0
- package/lib/esm/entities/index.js +1 -0
- package/lib/esm/entities/midnight/midnight.d.ts +2 -2
- package/lib/esm/{actions/requirements/blue/getBlueBundlesV1TokenRequirements.d.ts → entities/requirements/getBundlesTokenRequirements.d.ts} +21 -14
- package/lib/esm/{actions/requirements/blue/getBlueBundlesV1TokenRequirements.js → entities/requirements/getBundlesTokenRequirements.js} +51 -55
- package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.d.ts +28 -0
- package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.js +70 -0
- package/lib/esm/entities/requirements/index.d.ts +1 -0
- package/lib/esm/entities/requirements/index.js +1 -0
- package/lib/esm/entities/vaultV1/vaultV1.d.ts +348 -98
- package/lib/esm/entities/vaultV1/vaultV1.js +326 -124
- package/lib/esm/entities/vaultV2/vaultV2.d.ts +221 -68
- package/lib/esm/entities/vaultV2/vaultV2.js +222 -80
- package/lib/esm/helpers/index.d.ts +2 -1
- package/lib/esm/helpers/index.js +2 -1
- package/lib/esm/helpers/referralFee.d.ts +21 -0
- package/lib/esm/helpers/referralFee.js +31 -0
- package/lib/esm/helpers/slippage.d.ts +90 -1
- package/lib/esm/helpers/slippage.js +122 -2
- package/lib/esm/helpers/validate.d.ts +2 -0
- package/lib/esm/helpers/validate.js +11 -1
- package/lib/esm/helpers/validateRequirementSpender.d.ts +1 -1
- package/lib/esm/helpers/validateRequirementSpender.js +1 -0
- package/lib/esm/index.d.ts +1 -0
- package/lib/esm/index.js +1 -0
- package/lib/esm/types/action.d.ts +179 -70
- package/lib/esm/types/action.js +11 -11
- package/lib/esm/types/error.d.ts +62 -14
- package/lib/esm/types/error.js +80 -16
- package/package.json +3 -3
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.computeVaultMaxShareAllowance = exports.computeVaultMaxSharePrice = void 0;
|
|
3
4
|
exports.computeMinBorrowSharePrice = computeMinBorrowSharePrice;
|
|
4
5
|
exports.computeMaxRepaySharePrice = computeMaxRepaySharePrice;
|
|
5
6
|
exports.computeMaxSupplySharePrice = computeMaxSupplySharePrice;
|
|
@@ -7,6 +8,7 @@ exports.computeMinWithdrawSharePrice = computeMinWithdrawSharePrice;
|
|
|
7
8
|
const blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
8
9
|
const index_js_1 = require("../types/index.js");
|
|
9
10
|
const constant_js_1 = require("./constant.js");
|
|
11
|
+
const validate_js_1 = require("./validate.js");
|
|
10
12
|
/**
|
|
11
13
|
* Computes the minimum borrow share price (in RAY, 1e27) for slippage protection.
|
|
12
14
|
*
|
|
@@ -153,3 +155,124 @@ function computeMinWithdrawSharePrice(params) {
|
|
|
153
155
|
}
|
|
154
156
|
return blue_sdk_1.MathLib.mulDivDown(assets, blue_sdk_1.MathLib.wToRay(blue_sdk_1.MathLib.WAD - slippageTolerance), shares);
|
|
155
157
|
}
|
|
158
|
+
/**
|
|
159
|
+
* Computes the RAY-scaled maximum share price for a VaultBundlesV1 deposit leg.
|
|
160
|
+
*
|
|
161
|
+
* Previews shares on both the supplied Vault V1 or Vault V2 snapshot and its deadline-accrued
|
|
162
|
+
* counterpart, dividing by the smaller of the two so the bound covers the highest price the
|
|
163
|
+
* bundle may execute at. Shares are previewed rounding down, mirroring the ERC-4626 `deposit()`
|
|
164
|
+
* shares the on-chain `maxSharePrice` check divides by.
|
|
165
|
+
*
|
|
166
|
+
* @param params - Vault snapshot, bundles execution deadline, net assets, and slippage.
|
|
167
|
+
* @param params.vaultData - Hydrated Vault V1 `AccrualVault` or Vault V2 `AccrualVaultV2` snapshot.
|
|
168
|
+
* @param params.deadline - Bundle execution deadline as a Unix timestamp in seconds, used for accrual.
|
|
169
|
+
* @param params.assets - Net assets deposited after referral fees, in the underlying token's smallest unit.
|
|
170
|
+
* @param params.slippageTolerance - Accepted share-price increase as a WAD-scaled fraction (`1e18` = 100%).
|
|
171
|
+
* @returns The capped maximum share price enforced by VaultBundlesV1.
|
|
172
|
+
* @throws {NonPositiveInputError} when `assets` or the previewed shares are not positive.
|
|
173
|
+
* @throws {NegativeInputError} when `slippageTolerance` is negative.
|
|
174
|
+
* @throws {ExcessiveSlippageToleranceError} when `slippageTolerance` exceeds the SDK maximum.
|
|
175
|
+
* @example
|
|
176
|
+
* ```ts
|
|
177
|
+
* import { fetchAccrualVault } from "@morpho-org/blue-sdk-viem";
|
|
178
|
+
* import { computeVaultMaxSharePrice } from "@morpho-org/morpho-sdk";
|
|
179
|
+
* import { createPublicClient, http } from "viem";
|
|
180
|
+
* import { mainnet } from "viem/chains";
|
|
181
|
+
*
|
|
182
|
+
* const client = createPublicClient({ chain: mainnet, transport: http() });
|
|
183
|
+
* const vaultData = await fetchAccrualVault(
|
|
184
|
+
* "0xBEEF01735c132Ada46AA9aA4c54623cAA92A64CB",
|
|
185
|
+
* client,
|
|
186
|
+
* );
|
|
187
|
+
* const { timestamp } = await client.getBlock();
|
|
188
|
+
* const maxSharePrice = computeVaultMaxSharePrice({
|
|
189
|
+
* vaultData,
|
|
190
|
+
* deadline: timestamp + 7_200n,
|
|
191
|
+
* assets: 1_000_000n,
|
|
192
|
+
* slippageTolerance: 500_000_000_000_000n,
|
|
193
|
+
* });
|
|
194
|
+
* // maxSharePrice satisfies bigint
|
|
195
|
+
* ```
|
|
196
|
+
*/
|
|
197
|
+
const computeVaultMaxSharePrice = (params) => {
|
|
198
|
+
if (params.assets <= 0n) {
|
|
199
|
+
throw new index_js_1.NonPositiveInputError("assets", params.assets);
|
|
200
|
+
}
|
|
201
|
+
(0, validate_js_1.validateSlippageTolerance)(params.slippageTolerance);
|
|
202
|
+
const accrualTimestamp = params.vaultData instanceof blue_sdk_1.AccrualVaultV2
|
|
203
|
+
? blue_sdk_1.MathLib.max(params.deadline, params.vaultData.lastUpdate)
|
|
204
|
+
: params.deadline;
|
|
205
|
+
const accruedVault = params.vaultData instanceof blue_sdk_1.AccrualVaultV2
|
|
206
|
+
? params.vaultData.accrueInterest(accrualTimestamp).vault
|
|
207
|
+
: params.vaultData.accrueInterest(accrualTimestamp);
|
|
208
|
+
// The deadline snapshot is not necessarily the highest price over `[now, deadline]`: Vault V2
|
|
209
|
+
// charges its management fee regardless of yield, minting shares against an unchanged
|
|
210
|
+
// `_totalAssets`, so an idle vault's price *declines*. Bound at the maximum price across both
|
|
211
|
+
// endpoints — the minimum previewed shares — mirroring the `max(current, accrued)` shares the
|
|
212
|
+
// sibling `computeVaultMaxShareAllowance` authorizes.
|
|
213
|
+
const shares = blue_sdk_1.MathLib.min(params.vaultData.toShares(params.assets, "Down"), accruedVault.toShares(params.assets, "Down"));
|
|
214
|
+
if (shares <= 0n) {
|
|
215
|
+
throw new index_js_1.NonPositiveInputError("shares", shares);
|
|
216
|
+
}
|
|
217
|
+
return blue_sdk_1.MathLib.min(blue_sdk_1.MathLib.mulDivUp(params.assets, blue_sdk_1.MathLib.wToRay(blue_sdk_1.MathLib.WAD + params.slippageTolerance), shares), constant_js_1.MAX_ABSOLUTE_SHARE_PRICE);
|
|
218
|
+
};
|
|
219
|
+
exports.computeVaultMaxSharePrice = computeVaultMaxSharePrice;
|
|
220
|
+
/**
|
|
221
|
+
* Computes the exact vault-share authorization cap for an asset-denominated exit.
|
|
222
|
+
*
|
|
223
|
+
* The cap covers both the current and deadline-accrued preview. Vault V2 and MetaMorpho 1.0 divide
|
|
224
|
+
* by `1 - slippageTolerance`, rounding up, to cover a share-price decline before inclusion;
|
|
225
|
+
* MetaMorpho 1.1's `lostAssets` clamp keeps that preview upper-bounded without widening it.
|
|
226
|
+
*
|
|
227
|
+
* @param params - Vault snapshot, execution deadline, asset amount, and WAD-scaled slippage.
|
|
228
|
+
* @param params.vaultData - Hydrated Vault V1 `AccrualVault` or Vault V2 `AccrualVaultV2` snapshot.
|
|
229
|
+
* @param params.deadline - Bundle execution deadline as a Unix timestamp in seconds, used for accrual.
|
|
230
|
+
* @param params.assets - Assets withdrawn from the vault, in the underlying token's smallest unit.
|
|
231
|
+
* @param params.slippageTolerance - Accepted share-price decline as a WAD-scaled fraction (`1e18` = 100%).
|
|
232
|
+
* @returns The maximum shares the prepared operation may burn.
|
|
233
|
+
* @throws {NonPositiveInputError} when `assets` or the computed share cap is not positive.
|
|
234
|
+
* @throws {NegativeInputError} when `slippageTolerance` is negative.
|
|
235
|
+
* @throws {ExcessiveSlippageToleranceError} when `slippageTolerance` exceeds the SDK maximum.
|
|
236
|
+
* @example
|
|
237
|
+
* ```ts
|
|
238
|
+
* import { fetchAccrualVault } from "@morpho-org/blue-sdk-viem";
|
|
239
|
+
* import { computeVaultMaxShareAllowance } from "@morpho-org/morpho-sdk";
|
|
240
|
+
* import { createPublicClient, http } from "viem";
|
|
241
|
+
* import { mainnet } from "viem/chains";
|
|
242
|
+
*
|
|
243
|
+
* const client = createPublicClient({ chain: mainnet, transport: http() });
|
|
244
|
+
* const vaultData = await fetchAccrualVault(
|
|
245
|
+
* "0xBEEF01735c132Ada46AA9aA4c54623cAA92A64CB",
|
|
246
|
+
* client,
|
|
247
|
+
* );
|
|
248
|
+
* const { timestamp } = await client.getBlock();
|
|
249
|
+
* const shares = computeVaultMaxShareAllowance({
|
|
250
|
+
* vaultData,
|
|
251
|
+
* deadline: timestamp + 7_200n,
|
|
252
|
+
* assets: 1_000_000n,
|
|
253
|
+
* slippageTolerance: 500_000_000_000_000n,
|
|
254
|
+
* });
|
|
255
|
+
* // shares is the exact allowance or permit value for the prepared exit.
|
|
256
|
+
* ```
|
|
257
|
+
*/
|
|
258
|
+
const computeVaultMaxShareAllowance = (params) => {
|
|
259
|
+
if (params.assets <= 0n) {
|
|
260
|
+
throw new index_js_1.NonPositiveInputError("assets", params.assets);
|
|
261
|
+
}
|
|
262
|
+
(0, validate_js_1.validateSlippageTolerance)(params.slippageTolerance);
|
|
263
|
+
const isVaultV2 = params.vaultData instanceof blue_sdk_1.AccrualVaultV2;
|
|
264
|
+
const accruedVault = isVaultV2
|
|
265
|
+
? params.vaultData.accrueInterest(blue_sdk_1.MathLib.max(params.deadline, params.vaultData.lastUpdate)).vault
|
|
266
|
+
: params.vaultData.accrueInterest(params.deadline);
|
|
267
|
+
const previewedShares = blue_sdk_1.MathLib.max(params.vaultData.toShares(params.assets, "Up"), accruedVault.toShares(params.assets, "Up"));
|
|
268
|
+
if (previewedShares <= 0n) {
|
|
269
|
+
throw new index_js_1.NonPositiveInputError("shares", previewedShares);
|
|
270
|
+
}
|
|
271
|
+
const needsLossBuffer = isVaultV2 ||
|
|
272
|
+
!("lostAssets" in params.vaultData) ||
|
|
273
|
+
params.vaultData.lostAssets == null;
|
|
274
|
+
return needsLossBuffer
|
|
275
|
+
? blue_sdk_1.MathLib.wDivUp(previewedShares, blue_sdk_1.MathLib.WAD - params.slippageTolerance)
|
|
276
|
+
: previewedShares;
|
|
277
|
+
};
|
|
278
|
+
exports.computeVaultMaxShareAllowance = computeVaultMaxShareAllowance;
|
|
@@ -108,6 +108,8 @@ export declare const validateChainId: (clientChainId: number | undefined, expect
|
|
|
108
108
|
* @throws {NativeAmountOnNonWNativeAssetError} if the asset is not wNative.
|
|
109
109
|
*/
|
|
110
110
|
export declare const validateNativeAsset: (chainId: number, asset: Address) => void;
|
|
111
|
+
/** @internal Validates native funding against a vault's wrapped-native asset. */
|
|
112
|
+
export declare const validateNativeVaultAsset: (chainId: number, vaultAsset: Address) => void;
|
|
111
113
|
/**
|
|
112
114
|
* Validates that the resulting position stays within the safe LTV threshold
|
|
113
115
|
* (LLTV minus buffer) after withdrawing collateral.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.validateWithdrawShares = exports.validateWithdrawAmount = exports.validateSlippageTolerance = exports.validateVaultV2BlueReallocations = exports.validateReallocations = exports.validateRepayShares = exports.validateRepayAmount = exports.validatePositionHealthAfterWithdraw = exports.validateNativeAsset = exports.validateChainId = exports.validatePositionHealth = exports.validateAccrualPosition = exports.validateMidnightMarketChainId = exports.validateUint256Field = exports.compareMarketIds = void 0;
|
|
3
|
+
exports.validateWithdrawShares = exports.validateWithdrawAmount = exports.validateSlippageTolerance = exports.validateVaultV2BlueReallocations = exports.validateReallocations = exports.validateRepayShares = exports.validateRepayAmount = exports.validatePositionHealthAfterWithdraw = exports.validateNativeVaultAsset = exports.validateNativeAsset = exports.validateChainId = exports.validatePositionHealth = exports.validateAccrualPosition = exports.validateMidnightMarketChainId = exports.validateUint256Field = exports.compareMarketIds = void 0;
|
|
4
4
|
exports.validateUserAddress = validateUserAddress;
|
|
5
5
|
const blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
6
6
|
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
@@ -169,6 +169,17 @@ const validateNativeAsset = (chainId, asset) => {
|
|
|
169
169
|
}
|
|
170
170
|
};
|
|
171
171
|
exports.validateNativeAsset = validateNativeAsset;
|
|
172
|
+
/** @internal Validates native funding against a vault's wrapped-native asset. */
|
|
173
|
+
const validateNativeVaultAsset = (chainId, vaultAsset) => {
|
|
174
|
+
const { wNative } = (0, blue_sdk_1.getChainAddresses)(chainId);
|
|
175
|
+
if (!(0, morpho_ts_1.isDefined)(wNative)) {
|
|
176
|
+
throw new index_js_1.ChainWNativeMissingError(chainId);
|
|
177
|
+
}
|
|
178
|
+
if (!(0, viem_1.isAddressEqual)(vaultAsset, wNative)) {
|
|
179
|
+
throw new index_js_1.NativeAmountOnNonWNativeVaultError(vaultAsset, wNative);
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
exports.validateNativeVaultAsset = validateNativeVaultAsset;
|
|
172
183
|
/**
|
|
173
184
|
* Validates that the resulting position stays within the safe LTV threshold
|
|
174
185
|
* (LLTV minus buffer) after withdrawing collateral.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type Address } from "@morpho-org/blue-sdk";
|
|
2
2
|
/** Supported spender slots that can be validated against the chain address registry. */
|
|
3
|
-
export type RequirementSpenderKey = "generalAdapter1" | "permit2" | "midnight" | "midnightBundles" | "vaultExitBundlesV1" | "blueBundlesV1";
|
|
3
|
+
export type RequirementSpenderKey = "generalAdapter1" | "permit2" | "midnight" | "midnightBundles" | "vaultExitBundlesV1" | "vaultBundlesV1" | "blueBundlesV1";
|
|
4
4
|
/**
|
|
5
5
|
* Validates that a requirement encoder spender matches one of the allowed chain addresses.
|
|
6
6
|
*
|
|
@@ -34,6 +34,7 @@ const validateRequirementSpender = (params) => {
|
|
|
34
34
|
midnight,
|
|
35
35
|
midnightBundles,
|
|
36
36
|
vaultExitBundlesV1: bundles?.vaultExitBundlesV1,
|
|
37
|
+
vaultBundlesV1: bundles?.vaultBundlesV1,
|
|
37
38
|
blueBundlesV1: bundles?.blueBundlesV1,
|
|
38
39
|
};
|
|
39
40
|
const supportedSpenders = params.allowed.map((key) => addresses[key]);
|
package/lib/cjs/index.d.ts
CHANGED
package/lib/cjs/index.js
CHANGED
|
@@ -16,5 +16,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./actions/index.js"), exports);
|
|
18
18
|
__exportStar(require("./client/index.js"), exports);
|
|
19
|
+
__exportStar(require("./entities/requirements/index.js"), exports);
|
|
19
20
|
__exportStar(require("./helpers/index.js"), exports);
|
|
20
21
|
__exportStar(require("./types/index.js"), exports);
|
|
@@ -13,24 +13,58 @@ export interface ERC20ApprovalAction extends BaseAction<"erc20Approval", {
|
|
|
13
13
|
export interface ERC20PermitAction {
|
|
14
14
|
sign: (client: WalletClient, userAddress: Address) => Promise<Hex>;
|
|
15
15
|
}
|
|
16
|
+
/** Metadata for a direct Vault V2 deposit through VaultBundlesV1. */
|
|
16
17
|
export interface VaultV2DepositAction extends BaseAction<"vaultV2Deposit", {
|
|
17
|
-
vault
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
/** Destination vault receiving net assets; shares are minted to the transaction sender. */
|
|
19
|
+
readonly vault: Address;
|
|
20
|
+
/** Gross funding in asset base units, for either ERC-20 or native funding, before fees. */
|
|
21
|
+
readonly amount: bigint;
|
|
22
|
+
/** Maximum asset/share ratio scaled by 1e27, computed from net assets through the deadline. */
|
|
23
|
+
readonly maxSharePrice: bigint;
|
|
24
|
+
/** Native funding marker: equals `amount` and transaction `value` on native deposits; otherwise undefined. */
|
|
25
|
+
readonly nativeAmount?: bigint;
|
|
26
|
+
/** Referral fee fraction scaled by WAD (1e18); zero disables the fee. */
|
|
27
|
+
readonly referralFeePct: bigint;
|
|
28
|
+
/** Recipient of the referral fee; zero address when the fee is disabled by default. */
|
|
29
|
+
readonly referralFeeRecipient: Address;
|
|
30
|
+
/** Fee in asset base units: floor(amount * referralFeePct / WAD). */
|
|
31
|
+
readonly referralFeeAssets: bigint;
|
|
32
|
+
/** Assets deposited into the vault: amount minus referralFeeAssets. */
|
|
33
|
+
readonly netAssets: bigint;
|
|
34
|
+
/** Execution and token-permit expiration as a Unix timestamp in seconds. */
|
|
35
|
+
readonly deadline: bigint;
|
|
22
36
|
}> {
|
|
23
37
|
}
|
|
38
|
+
/** Metadata for an exact-assets Vault V2 withdrawal through VaultBundlesV1. */
|
|
24
39
|
export interface VaultV2WithdrawAction extends BaseAction<"vaultV2Withdraw", {
|
|
25
|
-
vault
|
|
26
|
-
|
|
27
|
-
|
|
40
|
+
/** Source vault whose shares are burned from the transaction sender. */
|
|
41
|
+
readonly vault: Address;
|
|
42
|
+
/** Gross withdrawal in asset base units, before the referral fee is deducted. */
|
|
43
|
+
readonly amount: bigint;
|
|
44
|
+
/** Referral fee fraction scaled by WAD (1e18); zero disables the fee. */
|
|
45
|
+
readonly referralFeePct: bigint;
|
|
46
|
+
/** Recipient of the referral fee; zero address when the fee is disabled by default. */
|
|
47
|
+
readonly referralFeeRecipient: Address;
|
|
48
|
+
/** Fee in asset base units: floor(amount * referralFeePct / WAD). */
|
|
49
|
+
readonly referralFeeAssets: bigint;
|
|
50
|
+
/** Assets received by the transaction sender: amount minus referralFeeAssets. */
|
|
51
|
+
readonly netAssets: bigint;
|
|
52
|
+
/** Execution and share-permit expiration as a Unix timestamp in seconds. */
|
|
53
|
+
readonly deadline: bigint;
|
|
28
54
|
}> {
|
|
29
55
|
}
|
|
56
|
+
/** Metadata for an exact-shares Vault V2 redemption through VaultBundlesV1. */
|
|
30
57
|
export interface VaultV2RedeemAction extends BaseAction<"vaultV2Redeem", {
|
|
31
|
-
vault
|
|
32
|
-
|
|
33
|
-
|
|
58
|
+
/** Source vault whose shares are burned from the transaction sender. */
|
|
59
|
+
readonly vault: Address;
|
|
60
|
+
/** Exact shares to burn, in vault-share base units. */
|
|
61
|
+
readonly shares: bigint;
|
|
62
|
+
/** Referral fee fraction scaled by WAD (1e18), deducted from redeemed assets; zero disables it. */
|
|
63
|
+
readonly referralFeePct: bigint;
|
|
64
|
+
/** Recipient of the referral fee; zero address when the fee is disabled by default. */
|
|
65
|
+
readonly referralFeeRecipient: Address;
|
|
66
|
+
/** Execution and share-permit expiration as a Unix timestamp in seconds. */
|
|
67
|
+
readonly deadline: bigint;
|
|
34
68
|
}> {
|
|
35
69
|
}
|
|
36
70
|
/** Metadata for a Vault V2 in-kind redemption into Morpho Blue supply positions. */
|
|
@@ -63,24 +97,58 @@ export interface VaultV2ForceRedeemAction extends BaseAction<"vaultV2ForceRedeem
|
|
|
63
97
|
onBehalf: Address;
|
|
64
98
|
}> {
|
|
65
99
|
}
|
|
100
|
+
/** Metadata for a direct Vault V1 deposit through VaultBundlesV1. */
|
|
66
101
|
export interface VaultV1DepositAction extends BaseAction<"vaultV1Deposit", {
|
|
67
|
-
vault
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
102
|
+
/** Destination vault receiving net assets; shares are minted to the transaction sender. */
|
|
103
|
+
readonly vault: Address;
|
|
104
|
+
/** Gross funding in asset base units, for either ERC-20 or native funding, before fees. */
|
|
105
|
+
readonly amount: bigint;
|
|
106
|
+
/** Maximum asset/share ratio scaled by 1e27, computed from net assets through the deadline. */
|
|
107
|
+
readonly maxSharePrice: bigint;
|
|
108
|
+
/** Native funding marker: equals `amount` and transaction `value` on native deposits; otherwise undefined. */
|
|
109
|
+
readonly nativeAmount?: bigint;
|
|
110
|
+
/** Referral fee fraction scaled by WAD (1e18); zero disables the fee. */
|
|
111
|
+
readonly referralFeePct: bigint;
|
|
112
|
+
/** Recipient of the referral fee; zero address when the fee is disabled by default. */
|
|
113
|
+
readonly referralFeeRecipient: Address;
|
|
114
|
+
/** Fee in asset base units: floor(amount * referralFeePct / WAD). */
|
|
115
|
+
readonly referralFeeAssets: bigint;
|
|
116
|
+
/** Assets deposited into the vault: amount minus referralFeeAssets. */
|
|
117
|
+
readonly netAssets: bigint;
|
|
118
|
+
/** Execution and token-permit expiration as a Unix timestamp in seconds. */
|
|
119
|
+
readonly deadline: bigint;
|
|
72
120
|
}> {
|
|
73
121
|
}
|
|
122
|
+
/** Metadata for an exact-assets Vault V1 withdrawal through VaultBundlesV1. */
|
|
74
123
|
export interface VaultV1WithdrawAction extends BaseAction<"vaultV1Withdraw", {
|
|
75
|
-
vault
|
|
76
|
-
|
|
77
|
-
|
|
124
|
+
/** Source vault whose shares are burned from the transaction sender. */
|
|
125
|
+
readonly vault: Address;
|
|
126
|
+
/** Gross withdrawal in asset base units, before the referral fee is deducted. */
|
|
127
|
+
readonly amount: bigint;
|
|
128
|
+
/** Referral fee fraction scaled by WAD (1e18); zero disables the fee. */
|
|
129
|
+
readonly referralFeePct: bigint;
|
|
130
|
+
/** Recipient of the referral fee; zero address when the fee is disabled by default. */
|
|
131
|
+
readonly referralFeeRecipient: Address;
|
|
132
|
+
/** Fee in asset base units: floor(amount * referralFeePct / WAD). */
|
|
133
|
+
readonly referralFeeAssets: bigint;
|
|
134
|
+
/** Assets received by the transaction sender: amount minus referralFeeAssets. */
|
|
135
|
+
readonly netAssets: bigint;
|
|
136
|
+
/** Execution and share-permit expiration as a Unix timestamp in seconds. */
|
|
137
|
+
readonly deadline: bigint;
|
|
78
138
|
}> {
|
|
79
139
|
}
|
|
140
|
+
/** Metadata for an exact-shares Vault V1 redemption through VaultBundlesV1. */
|
|
80
141
|
export interface VaultV1RedeemAction extends BaseAction<"vaultV1Redeem", {
|
|
81
|
-
vault
|
|
82
|
-
|
|
83
|
-
|
|
142
|
+
/** Source vault whose shares are burned from the transaction sender. */
|
|
143
|
+
readonly vault: Address;
|
|
144
|
+
/** Exact shares to burn, in vault-share base units. */
|
|
145
|
+
readonly shares: bigint;
|
|
146
|
+
/** Referral fee fraction scaled by WAD (1e18), deducted from redeemed assets; zero disables it. */
|
|
147
|
+
readonly referralFeePct: bigint;
|
|
148
|
+
/** Recipient of the referral fee; zero address when the fee is disabled by default. */
|
|
149
|
+
readonly referralFeeRecipient: Address;
|
|
150
|
+
/** Execution and share-permit expiration as a Unix timestamp in seconds. */
|
|
151
|
+
readonly deadline: bigint;
|
|
84
152
|
}> {
|
|
85
153
|
}
|
|
86
154
|
/** Metadata for a Vault V1 in-kind redemption into Morpho Blue supply positions. */
|
|
@@ -92,13 +160,28 @@ export interface VaultV1InKindRedeemAction extends BaseAction<"vaultV1InKindRede
|
|
|
92
160
|
readonly deadline: bigint;
|
|
93
161
|
}> {
|
|
94
162
|
}
|
|
163
|
+
/** Metadata for an assets-or-shares Vault V1 to Vault V2 migration through VaultBundlesV1. */
|
|
95
164
|
export interface VaultV1MigrateToV2Action extends BaseAction<"vaultV1MigrateToV2", {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
shares
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
165
|
+
/** Source Vault V1 whose shares are burned from the transaction sender. */
|
|
166
|
+
readonly sourceVault: Address;
|
|
167
|
+
/** Destination Vault V2 receiving net assets; shares are minted to the transaction sender. */
|
|
168
|
+
readonly targetVault: Address;
|
|
169
|
+
/** Gross assets to withdraw in asset base units; zero in exact-shares mode. */
|
|
170
|
+
readonly assets: bigint;
|
|
171
|
+
/** Source shares to burn in vault-share base units; zero in exact-assets mode. */
|
|
172
|
+
readonly shares: bigint;
|
|
173
|
+
/** Maximum destination asset base units per share base unit, scaled by RAY (1e27). */
|
|
174
|
+
readonly maxSharePriceVaultV2: bigint;
|
|
175
|
+
/** Referral fee fraction scaled by WAD (1e18), deducted before depositing; zero disables it. */
|
|
176
|
+
readonly referralFeePct: bigint;
|
|
177
|
+
/** Recipient of the referral fee; zero address when the fee is disabled by default. */
|
|
178
|
+
readonly referralFeeRecipient: Address;
|
|
179
|
+
/** Fee in asset base units: floor(assets * referralFeePct / WAD); omitted in exact-shares mode. */
|
|
180
|
+
readonly referralFeeAssets?: bigint;
|
|
181
|
+
/** Assets deposited: assets minus referralFeeAssets; omitted in exact-shares mode. */
|
|
182
|
+
readonly netAssets?: bigint;
|
|
183
|
+
/** Execution and source share-permit expiration as a Unix timestamp in seconds. */
|
|
184
|
+
readonly deadline: bigint;
|
|
102
185
|
}> {
|
|
103
186
|
}
|
|
104
187
|
/** Metadata for a direct BlueBundlesV1 loan-asset supply. */
|
|
@@ -297,7 +380,7 @@ export interface MidnightCancelOfferAction extends BaseAction<"midnightCancelOff
|
|
|
297
380
|
}> {
|
|
298
381
|
}
|
|
299
382
|
/** Metadata discriminators carried by transactions returned by the SDK. */
|
|
300
|
-
export type TransactionAction = ERC20ApprovalAction | VaultV2DepositAction | VaultV2WithdrawAction | VaultV2RedeemAction | VaultV2InKindRedeemAction | VaultV2ForceWithdrawAction | VaultV2ForceRedeemAction | VaultV1DepositAction | VaultV1WithdrawAction | VaultV1RedeemAction | VaultV1InKindRedeemAction | VaultV1MigrateToV2Action | BlueSupplyAction |
|
|
383
|
+
export type TransactionAction = ERC20ApprovalAction | VaultV2DepositAction | VaultV2WithdrawAction | VaultV2RedeemAction | VaultV2InKindRedeemAction | VaultV2ForceWithdrawAction | VaultV2ForceRedeemAction | VaultV1DepositAction | VaultV1WithdrawAction | VaultV1RedeemAction | VaultV1InKindRedeemAction | VaultV1MigrateToV2Action | BlueSupplyAction | BlueSupplyCollateralAction | BlueBorrowAction | BlueSupplyCollateralBorrowAction | BlueRepayAction | BlueWithdrawCollateralAction | BlueRepayWithdrawCollateralAction | BlueWithdrawAction | BlueRefinanceAction | BlueAuthorizationAction | MidnightAuthorizationAction | SetterRatifierRatifyRootAction | MidnightTakeLendAction | MidnightTakeBorrowAction | MidnightSupplyCollateralTakeBorrowAction | MidnightSupplyCollateralAction | MempoolSubmitOffersAction | MidnightRedeemAction | MidnightRepayWithdrawCollateralAction | MidnightCancelOfferAction;
|
|
301
384
|
export interface Transaction<TAction extends BaseAction = TransactionAction> {
|
|
302
385
|
readonly to: Address;
|
|
303
386
|
readonly value: bigint;
|
|
@@ -318,22 +401,45 @@ export type DepositAmountArgs = {
|
|
|
318
401
|
nativeAmount: bigint;
|
|
319
402
|
amount?: bigint;
|
|
320
403
|
};
|
|
404
|
+
/** Mutually exclusive ERC-20 or native funding accepted by fixed bundles entrypoints. */
|
|
405
|
+
export type BundlesFundingArgs = {
|
|
406
|
+
readonly amount: bigint;
|
|
407
|
+
readonly nativeAmount?: never;
|
|
408
|
+
} | {
|
|
409
|
+
readonly nativeAmount: bigint;
|
|
410
|
+
readonly amount?: never;
|
|
411
|
+
};
|
|
412
|
+
/** Controls token requirements generated for a bundles-funded action. */
|
|
413
|
+
export interface BundlesTokenRequirementsOptions {
|
|
414
|
+
/** Prefer ERC-2612 when the funded token exposes a compatible nonce. */
|
|
415
|
+
readonly useSimplePermit?: boolean;
|
|
416
|
+
/** Explicit unused Permit2 SignatureTransfer unordered nonce. */
|
|
417
|
+
readonly permit2Nonce?: bigint;
|
|
418
|
+
}
|
|
419
|
+
/** Mutually exclusive source amount accepted by a Vault V1 to Vault V2 migration. */
|
|
420
|
+
export type VaultV1MigrateToV2AmountArgs = {
|
|
421
|
+
readonly shares: bigint;
|
|
422
|
+
readonly assets?: never;
|
|
423
|
+
} | {
|
|
424
|
+
readonly assets: bigint;
|
|
425
|
+
readonly shares?: never;
|
|
426
|
+
};
|
|
321
427
|
export interface PermitArgs {
|
|
322
|
-
owner: Address;
|
|
323
|
-
nonce: bigint;
|
|
324
|
-
asset: Address;
|
|
325
|
-
signature: Hex;
|
|
326
|
-
amount: bigint;
|
|
327
|
-
deadline: bigint;
|
|
428
|
+
readonly owner: Address;
|
|
429
|
+
readonly nonce: bigint;
|
|
430
|
+
readonly asset: Address;
|
|
431
|
+
readonly signature: Hex;
|
|
432
|
+
readonly amount: bigint;
|
|
433
|
+
readonly deadline: bigint;
|
|
328
434
|
}
|
|
329
435
|
export interface Permit2Args {
|
|
330
|
-
owner: Address;
|
|
331
|
-
nonce: bigint;
|
|
332
|
-
asset: Address;
|
|
333
|
-
signature: Hex;
|
|
334
|
-
amount: bigint;
|
|
335
|
-
deadline: bigint;
|
|
336
|
-
expiration: bigint;
|
|
436
|
+
readonly owner: Address;
|
|
437
|
+
readonly nonce: bigint;
|
|
438
|
+
readonly asset: Address;
|
|
439
|
+
readonly signature: Hex;
|
|
440
|
+
readonly amount: bigint;
|
|
441
|
+
readonly deadline: bigint;
|
|
442
|
+
readonly expiration: bigint;
|
|
337
443
|
}
|
|
338
444
|
/**
|
|
339
445
|
* Signed Morpho Blue authorization payload produced when an integrator opts into offchain
|
|
@@ -362,9 +468,11 @@ export interface MidnightOfferRootSignatureArgs {
|
|
|
362
468
|
readonly payload: Hex;
|
|
363
469
|
}
|
|
364
470
|
export interface PermitAction extends BaseAction<"permit", {
|
|
365
|
-
spender: Address;
|
|
366
|
-
amount: bigint;
|
|
367
|
-
deadline: bigint;
|
|
471
|
+
readonly spender: Address;
|
|
472
|
+
readonly amount: bigint;
|
|
473
|
+
readonly deadline: bigint;
|
|
474
|
+
/** Permit nonce captured by a prepared requirement, when available. */
|
|
475
|
+
readonly nonce?: bigint;
|
|
368
476
|
}> {
|
|
369
477
|
}
|
|
370
478
|
export interface Permit2Action extends BaseAction<"permit2", {
|
|
@@ -374,10 +482,11 @@ export interface Permit2Action extends BaseAction<"permit2", {
|
|
|
374
482
|
expiration: bigint;
|
|
375
483
|
}> {
|
|
376
484
|
}
|
|
377
|
-
/** Signable Permit2 SignatureTransfer requirement for a
|
|
378
|
-
export interface
|
|
485
|
+
/** Signable Permit2 SignatureTransfer requirement for a fixed bundles token pull. */
|
|
486
|
+
export interface Permit2SignatureTransferAction extends BaseAction<"permit2SignatureTransfer", {
|
|
379
487
|
readonly spender: Address;
|
|
380
488
|
readonly amount: bigint;
|
|
489
|
+
readonly nonce: bigint;
|
|
381
490
|
readonly deadline: bigint;
|
|
382
491
|
}> {
|
|
383
492
|
}
|
|
@@ -399,7 +508,7 @@ export interface MidnightOfferRootSignatureAction extends BaseAction<"midnightOf
|
|
|
399
508
|
}> {
|
|
400
509
|
}
|
|
401
510
|
/** Action metadata supported by signature requirements. */
|
|
402
|
-
export type SignatureRequirementAction = PermitAction | Permit2Action |
|
|
511
|
+
export type SignatureRequirementAction = PermitAction | Permit2Action | Permit2SignatureTransferAction | AuthorizationAction | MidnightOfferRootSignatureAction;
|
|
403
512
|
/** Argument payloads returned by signature requirements. */
|
|
404
513
|
export type RequirementSignatureArgs = PermitArgs | Permit2Args | AuthorizationSignatureArgs | MidnightOfferRootSignatureArgs;
|
|
405
514
|
/** A signed ERC-2612 permit requirement. */
|
|
@@ -414,10 +523,10 @@ export interface Permit2AllowanceRequirementSignature {
|
|
|
414
523
|
}
|
|
415
524
|
/** A signed ERC-2612 permit or Permit2 AllowanceTransfer requirement. */
|
|
416
525
|
export type PermitRequirementSignature = Erc2612RequirementSignature | Permit2AllowanceRequirementSignature;
|
|
417
|
-
/** A signed Permit2 SignatureTransfer requirement used by
|
|
418
|
-
export interface
|
|
526
|
+
/** A signed Permit2 SignatureTransfer requirement used by fixed bundles contracts. */
|
|
527
|
+
export interface Permit2SignatureTransferRequirementSignature {
|
|
419
528
|
readonly args: Readonly<PermitArgs>;
|
|
420
|
-
readonly action:
|
|
529
|
+
readonly action: Permit2SignatureTransferAction;
|
|
421
530
|
}
|
|
422
531
|
/** A signed Morpho authorization consumed by Bundler3 or a direct BlueBundlesV1 call. */
|
|
423
532
|
export interface AuthorizationRequirementSignature {
|
|
@@ -431,14 +540,14 @@ export interface MidnightOfferRootSignature {
|
|
|
431
540
|
}
|
|
432
541
|
/**
|
|
433
542
|
* The deep-frozen output of `Requirement.sign()`. Discriminated on `action.type`:
|
|
434
|
-
* `"permit"` / `"permit2"` carry token-approval args, `"
|
|
435
|
-
*
|
|
543
|
+
* `"permit"` / `"permit2"` carry token-approval args, `"permit2SignatureTransfer"` carries a
|
|
544
|
+
* bundles SignatureTransfer, `"authorization"` carries the signed Morpho authorization,
|
|
436
545
|
* and Midnight adds `"midnightOfferRootSignature"`.
|
|
437
546
|
*/
|
|
438
547
|
export type RequirementSignature<TAction extends SignatureRequirementAction | undefined = undefined, TArgs extends RequirementSignatureArgs | undefined = undefined> = TAction extends SignatureRequirementAction ? TArgs extends RequirementSignatureArgs ? {
|
|
439
548
|
args: TArgs;
|
|
440
549
|
action: TAction;
|
|
441
|
-
} : never : PermitRequirementSignature |
|
|
550
|
+
} : never : PermitRequirementSignature | Permit2SignatureTransferRequirementSignature | AuthorizationRequirementSignature | MidnightOfferRootSignature;
|
|
442
551
|
type RequirementResult<TSignatureOrAction extends RequirementSignature | SignatureRequirementAction, TArgs extends RequirementSignatureArgs | undefined> = TSignatureOrAction extends SignatureRequirementAction ? RequirementSignature<TSignatureOrAction, Extract<TArgs, RequirementSignatureArgs>> : Extract<TSignatureOrAction, RequirementSignature>;
|
|
443
552
|
/**
|
|
444
553
|
* A signable approval / authorization requirement. `sign()` returns the matching
|
|
@@ -455,18 +564,18 @@ export interface Requirement<TSignatureOrAction extends RequirementSignature | S
|
|
|
455
564
|
}
|
|
456
565
|
/** Bundler3 token signature requirement. */
|
|
457
566
|
export type Bundler3TokenSignatureRequirement = Requirement<PermitRequirementSignature>;
|
|
458
|
-
/**
|
|
459
|
-
export type
|
|
567
|
+
/** ERC-2612 or Permit2 SignatureTransfer requirement consumed by a fixed bundles contract. */
|
|
568
|
+
export type BundlesTokenSignatureRequirement = Requirement<BundlesTokenRequirementSignature>;
|
|
460
569
|
/** Midnight Ecrecover offer-root signature requirement. */
|
|
461
570
|
export type MidnightOfferRootRequirement = Requirement<MidnightOfferRootSignatureAction, MidnightOfferRootSignatureArgs>;
|
|
462
571
|
/** Any token signature requirement supported by an SDK transaction route. */
|
|
463
|
-
export type TokenSignatureRequirement = Bundler3TokenSignatureRequirement |
|
|
572
|
+
export type TokenSignatureRequirement = Bundler3TokenSignatureRequirement | BundlesTokenSignatureRequirement;
|
|
464
573
|
/** Bundler3 token signature result. */
|
|
465
574
|
export type Bundler3TokenRequirementSignature = PermitRequirementSignature;
|
|
466
|
-
/**
|
|
467
|
-
export type
|
|
575
|
+
/** Token signature result consumed by a fixed bundles contract. */
|
|
576
|
+
export type BundlesTokenRequirementSignature = Erc2612RequirementSignature | Permit2SignatureTransferRequirementSignature;
|
|
468
577
|
/** Any token signature result supported by an SDK transaction route. */
|
|
469
|
-
export type TokenRequirementSignature = Bundler3TokenRequirementSignature |
|
|
578
|
+
export type TokenRequirementSignature = Bundler3TokenRequirementSignature | BundlesTokenRequirementSignature;
|
|
470
579
|
/** Any signature result returned by an action-output signature requirement. */
|
|
471
580
|
export type AnyRequirementSignature = TokenRequirementSignature | AuthorizationRequirementSignature | MidnightOfferRootSignature;
|
|
472
581
|
/** Any signature requirement returned by an entity action output. */
|
|
@@ -508,19 +617,19 @@ export declare function isPermitSignature(signature: RequirementSignature): sign
|
|
|
508
617
|
* Narrows a {@link RequirementSignature} to a Permit2 SignatureTransfer result.
|
|
509
618
|
*
|
|
510
619
|
* @param signature - The signed requirement to test.
|
|
511
|
-
* @returns `true` when `signature.action.type` is `"
|
|
620
|
+
* @returns `true` when `signature.action.type` is `"permit2SignatureTransfer"`.
|
|
512
621
|
* @example
|
|
513
622
|
* ```ts
|
|
514
623
|
* import {
|
|
515
|
-
*
|
|
624
|
+
* isPermit2SignatureTransferSignature,
|
|
516
625
|
* type RequirementSignature,
|
|
517
626
|
* } from "@morpho-org/morpho-sdk";
|
|
518
627
|
*
|
|
519
628
|
* const getPermit2Nonce = (signature: RequirementSignature): bigint | undefined =>
|
|
520
|
-
*
|
|
629
|
+
* isPermit2SignatureTransferSignature(signature) ? signature.args.nonce : undefined;
|
|
521
630
|
* ```
|
|
522
631
|
*/
|
|
523
|
-
export declare function
|
|
632
|
+
export declare function isPermit2SignatureTransferSignature(signature: RequirementSignature): signature is Permit2SignatureTransferRequirementSignature;
|
|
524
633
|
/**
|
|
525
634
|
* Narrows a {@link RequirementSignature} to a signed Morpho authorization.
|
|
526
635
|
*
|
|
@@ -540,7 +649,7 @@ export interface SelectedRequirementSignatures {
|
|
|
540
649
|
/** The single ERC-2612 or Permit2 AllowanceTransfer signature, when present. */
|
|
541
650
|
readonly permit?: PermitRequirementSignature;
|
|
542
651
|
/** The single Permit2 SignatureTransfer signature, when present. */
|
|
543
|
-
readonly
|
|
652
|
+
readonly permit2SignatureTransfer?: Permit2SignatureTransferRequirementSignature;
|
|
544
653
|
/** The single Morpho authorization signature, when present. */
|
|
545
654
|
readonly authorization?: AuthorizationRequirementSignature;
|
|
546
655
|
/** The single Midnight offer-root signature, when present. */
|
|
@@ -558,7 +667,7 @@ export interface SelectedRequirementSignatures {
|
|
|
558
667
|
* @param signatures - The signatures passed to `buildTx`.
|
|
559
668
|
* @param accepts - Which signature kinds this operation consumes.
|
|
560
669
|
* @param accepts.permit - Whether an ERC-2612 or Permit2 AllowanceTransfer signature is consumed.
|
|
561
|
-
* @param accepts.
|
|
670
|
+
* @param accepts.permit2SignatureTransfer - Whether a Permit2 SignatureTransfer is consumed.
|
|
562
671
|
* @param accepts.authorization - Whether a Morpho authorization signature is consumed.
|
|
563
672
|
* @param accepts.midnightOfferRoot - Whether a Midnight offer-root signature is consumed.
|
|
564
673
|
* @returns The accepted signature in each typed slot, when present.
|
|
@@ -575,9 +684,9 @@ export interface SelectedRequirementSignatures {
|
|
|
575
684
|
* ```
|
|
576
685
|
*/
|
|
577
686
|
export declare function selectRequirementSignatures(signatures: readonly RequirementSignature[] | undefined, accepts: {
|
|
578
|
-
permit?: boolean;
|
|
579
|
-
|
|
580
|
-
authorization?: boolean;
|
|
581
|
-
midnightOfferRoot?: boolean;
|
|
687
|
+
readonly permit?: boolean;
|
|
688
|
+
readonly permit2SignatureTransfer?: boolean;
|
|
689
|
+
readonly authorization?: boolean;
|
|
690
|
+
readonly midnightOfferRoot?: boolean;
|
|
582
691
|
}): SelectedRequirementSignatures;
|
|
583
692
|
export {};
|