@morpho-org/morpho-sdk 9.3.0 → 9.5.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 +7 -0
- package/MIGRATION-v7-to-v8.md +7 -0
- package/MIGRATION-v8-to-v9.md +7 -0
- package/README.md +9 -5
- package/lib/cjs/abis.d.ts +2 -2
- package/lib/cjs/abis.js +4 -1
- package/lib/cjs/actions/blue/index.d.ts +1 -0
- package/lib/cjs/actions/blue/index.js +1 -0
- package/lib/cjs/actions/blue/withdrawBuyCallback.d.ts +60 -0
- package/lib/cjs/actions/blue/withdrawBuyCallback.js +79 -0
- package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.d.ts +1 -0
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +4 -1
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +4 -1
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +5 -1
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +1 -0
- package/lib/cjs/blue/abis.d.ts +1 -1
- package/lib/cjs/blue/abis.js +3 -1
- package/lib/cjs/client/morphoViemExtension.d.ts +1 -1
- package/lib/cjs/client/morphoViemExtension.js +1 -1
- package/lib/cjs/entities/blue/blue.d.ts +88 -23
- package/lib/cjs/entities/blue/blue.js +89 -22
- package/lib/cjs/entities/requirements/getBundlesTokenRequirements.d.ts +21 -25
- package/lib/cjs/entities/requirements/getBundlesTokenRequirements.js +50 -85
- package/lib/cjs/entities/requirements/getUnusedPermit2Nonce.d.ts +6 -3
- package/lib/cjs/entities/requirements/getUnusedPermit2Nonce.js +2 -2
- package/lib/cjs/entities/vaultV1/vaultV1.d.ts +5 -11
- package/lib/cjs/entities/vaultV1/vaultV1.js +3 -11
- package/lib/cjs/entities/vaultV2/vaultV2.d.ts +5 -11
- package/lib/cjs/entities/vaultV2/vaultV2.js +3 -11
- package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +3 -0
- package/lib/cjs/entities/vaultV2BlueReallocationData.js +40 -4
- package/lib/cjs/errors.d.ts +1 -1
- package/lib/cjs/errors.js +3 -1
- package/lib/cjs/midnight/abis.d.ts +1 -1
- package/lib/cjs/midnight/abis.js +2 -1
- package/lib/cjs/types/action.d.ts +26 -5
- package/lib/cjs/types/action.js +1 -0
- package/lib/cjs/types/error.d.ts +42 -2
- package/lib/cjs/types/error.js +49 -3
- package/lib/esm/abis.d.ts +2 -2
- package/lib/esm/abis.js +2 -2
- package/lib/esm/actions/blue/index.d.ts +1 -0
- package/lib/esm/actions/blue/index.js +1 -0
- package/lib/esm/actions/blue/withdrawBuyCallback.d.ts +60 -0
- package/lib/esm/actions/blue/withdrawBuyCallback.js +75 -0
- package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.d.ts +1 -0
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +4 -1
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +4 -1
- package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +5 -1
- package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +1 -0
- package/lib/esm/blue/abis.d.ts +1 -1
- package/lib/esm/blue/abis.js +1 -1
- package/lib/esm/client/morphoViemExtension.d.ts +1 -1
- package/lib/esm/client/morphoViemExtension.js +1 -1
- package/lib/esm/entities/blue/blue.d.ts +88 -23
- package/lib/esm/entities/blue/blue.js +91 -24
- package/lib/esm/entities/requirements/getBundlesTokenRequirements.d.ts +21 -25
- package/lib/esm/entities/requirements/getBundlesTokenRequirements.js +52 -87
- package/lib/esm/entities/requirements/getUnusedPermit2Nonce.d.ts +6 -3
- package/lib/esm/entities/requirements/getUnusedPermit2Nonce.js +2 -2
- package/lib/esm/entities/vaultV1/vaultV1.d.ts +5 -11
- package/lib/esm/entities/vaultV1/vaultV1.js +4 -12
- package/lib/esm/entities/vaultV2/vaultV2.d.ts +5 -11
- package/lib/esm/entities/vaultV2/vaultV2.js +4 -12
- package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +3 -0
- package/lib/esm/entities/vaultV2BlueReallocationData.js +40 -4
- package/lib/esm/errors.d.ts +1 -1
- package/lib/esm/errors.js +1 -1
- package/lib/esm/midnight/abis.d.ts +1 -1
- package/lib/esm/midnight/abis.js +1 -1
- package/lib/esm/types/action.d.ts +26 -5
- package/lib/esm/types/action.js +1 -0
- package/lib/esm/types/error.d.ts +42 -2
- package/lib/esm/types/error.js +43 -2
- package/package.json +5 -5
package/MIGRATION-v5-to-v6.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# Migrating `@morpho-org/morpho-sdk` from v5 to v6
|
|
2
2
|
|
|
3
|
+
> Current funding behavior: the SDK no longer requests Permit2 funding. Use ERC-2612 permits
|
|
4
|
+
> (`supportSignature: true`, with `useSimplePermit` defaulting to true) or direct ERC-20 approvals.
|
|
5
|
+
> Pass `useSimplePermit: false` to force approvals. The legacy
|
|
6
|
+
> `permit2Nonce` option is deprecated and ignored; builders still accept previously collected
|
|
7
|
+
> signatures. Permit2 requirement descriptions below document historical behavior.
|
|
8
|
+
|
|
9
|
+
|
|
3
10
|
Version 6 keeps the Blue entity at `client.morpho.blue(marketParams, chainId)` and preserves its
|
|
4
11
|
write-method names while routing them through five direct BlueBundlesV1 entrypoints. Blue reads and
|
|
5
12
|
the Vault V2 reallocation-data helper remain on the same entity. There is no parallel
|
package/MIGRATION-v7-to-v8.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# Migrating `@morpho-org/morpho-sdk` from v7 to v8
|
|
2
2
|
|
|
3
|
+
> Current funding behavior: the SDK no longer requests Permit2 funding. Use ERC-2612 permits
|
|
4
|
+
> (`supportSignature: true`, with `useSimplePermit` defaulting to true) or direct ERC-20 approvals.
|
|
5
|
+
> Pass `useSimplePermit: false` to force approvals. The legacy
|
|
6
|
+
> `permit2Nonce` option is deprecated and ignored; builders still accept previously collected
|
|
7
|
+
> signatures. Permit2 requirement descriptions below document historical behavior.
|
|
8
|
+
|
|
9
|
+
|
|
3
10
|
Version 8 makes token metadata and RPC-backed requirement reads fail closed.
|
|
4
11
|
These calls now throw typed errors instead of returning partial or default values.
|
|
5
12
|
|
package/MIGRATION-v8-to-v9.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# Migrating from morpho-sdk v8 to v9
|
|
2
2
|
|
|
3
|
+
> Current funding behavior: the SDK no longer requests Permit2 funding. Use ERC-2612 permits
|
|
4
|
+
> (`supportSignature: true`, with `useSimplePermit` defaulting to true) or direct ERC-20 approvals.
|
|
5
|
+
> Pass `useSimplePermit: false` to force approvals. The legacy
|
|
6
|
+
> `permit2Nonce` option is deprecated and ignored; builders still accept previously collected
|
|
7
|
+
> signatures. Permit2 requirement descriptions below document historical behavior.
|
|
8
|
+
|
|
9
|
+
|
|
3
10
|
Version 9 removes exact-amount approval controls. Classic ERC-20 approvals and vault-share
|
|
4
11
|
approvals or permits now use `maxUint256` when the existing allowance is below the required amount.
|
|
5
12
|
An allowance at or above the required amount satisfies the requirement; larger leftovers are
|
package/README.md
CHANGED
|
@@ -54,6 +54,7 @@ BlueBundlesV1, and the remaining rows identify their destination.
|
|
|
54
54
|
| | `forceRedeem` | Vault multicall |
|
|
55
55
|
| | `inKindRedeem` | VaultExitBundlesV1 |
|
|
56
56
|
| **Blue** | `supply`, `withdraw`, `supplyCollateral`, `borrow`, `supplyCollateralBorrow`, `repay`, `withdrawCollateral`, `repayWithdrawCollateral`, `refinance` | BlueBundlesV1 |
|
|
57
|
+
| **Blue** | `withdrawBuyCallback` | Morpho Blue (direct `withdraw` for a BlueBuyCallback's owner) |
|
|
57
58
|
| **Midnight** | `takeLend`, `takeBorrow`, `supplyCollateralTakeBorrow`, `takeRepayWithdrawCollateral`, `repayWithdrawCollateral`, `takeWithdraw` | MidnightBundlesV2 (Ethereum, Base, Arc, Robinhood, Tempo) |
|
|
58
59
|
| | `supplyCollateral`, `withdrawCollateral`, `redeem` | Direct call |
|
|
59
60
|
| | `makeLend`, `makeBorrow`, `makeWithdraw`, `makeRepay`, `supplyCollateralMakeBorrow`, `supplyBlueMakeLend`, `cancelOffers` | MidnightBundlesV2 (Ethereum, Base, Arc, Robinhood, Tempo) |
|
|
@@ -76,7 +77,8 @@ Robinhood Chain, Arc, and X Layer. Custom deployments can still be configured wi
|
|
|
76
77
|
## How it works
|
|
77
78
|
|
|
78
79
|
Actions that pull tokens or touch a position return `{ buildTx, getRequirements }`. All Blue
|
|
79
|
-
writes use this lazy shape while still encoding one direct BlueBundlesV1 call
|
|
80
|
+
writes use this lazy shape while still encoding one direct BlueBundlesV1 call, except
|
|
81
|
+
`withdrawBuyCallback`, which encodes one direct Morpho Blue `withdraw`. Vault deposits,
|
|
80
82
|
`withdraw`, and `redeem` use the same shape for token or vault-share authorization to
|
|
81
83
|
VaultBundlesV1. Vault `inKindRedeem` and `forceWithdraw` use it so callers can await
|
|
82
84
|
`getRequirements()` to check share authorization to VaultExitBundlesV1 — and, for `inKindRedeem`,
|
|
@@ -84,7 +86,7 @@ live Blue liquidity — before invoking `buildTx()`. Calling `buildTx()` directl
|
|
|
84
86
|
RPC-backed pre-flight checks. `forceRedeem` remains a direct Vault V2 multicall without
|
|
85
87
|
prerequisites.
|
|
86
88
|
|
|
87
|
-
- **`getRequirements()`** — async; the on-chain prerequisites to satisfy first: ERC-20 approvals, permit
|
|
89
|
+
- **`getRequirements()`** — async; the on-chain prerequisites to satisfy first: ERC-20 approvals, ERC-2612 permit signatures, Morpho authorization, or (for Midnight) operator authorization.
|
|
88
90
|
- **`buildTx(signatures?)`** — synchronous; the final, deep-frozen viem transaction. Pass any signatures collected from the requirements.
|
|
89
91
|
|
|
90
92
|
Every transaction carries `tx.action` — typed metadata describing the encoded call (`type` plus
|
|
@@ -109,7 +111,10 @@ const requirements = await getRequirements();
|
|
|
109
111
|
const tx = buildTx([permitSignature]);
|
|
110
112
|
```
|
|
111
113
|
|
|
112
|
-
Enable off-chain approvals (
|
|
114
|
+
Enable off-chain approvals (ERC-2612 permits) with `morphoViemExtension({ supportSignature: true })`. Pass `getRequirements({ useSimplePermit: false })` to force direct ERC-20 approvals; unsupported tokens also fall back to direct approvals.
|
|
115
|
+
|
|
116
|
+
Token funding checks the bundles allowance first on every route. If it already covers the amount,
|
|
117
|
+
no token requirement is returned and ERC-2612 support is not probed.
|
|
113
118
|
|
|
114
119
|
### `userAddress` is the eventual submitter
|
|
115
120
|
|
|
@@ -150,8 +155,7 @@ Create an entity — every factory takes a chain ID as its last argument:
|
|
|
150
155
|
### Vault deposit / withdraw
|
|
151
156
|
|
|
152
157
|
Deposit calls VaultBundlesV1 and may require an approval or permit. ERC-20 approvals and ERC-2612
|
|
153
|
-
permits authorize VaultBundlesV1.
|
|
154
|
-
while the ERC-20 approval prerequisite targets canonical Permit2.
|
|
158
|
+
permits authorize VaultBundlesV1. The SDK no longer requests Permit2 funding.
|
|
155
159
|
|
|
156
160
|
```typescript
|
|
157
161
|
const vault = client.morpho.vaultV2("0xVault...", 1);
|
package/lib/cjs/abis.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
export { marketParamsAbi as blueMarketParamsAbi } from "@morpho-org/blue-sdk";
|
|
2
|
-
export { adaptiveCurveIrmAbi as blueAdaptiveCurveIrmAbi, blueAbi, blueOracleAbi, erc2612Abi, erc5267Abi, metaMorphoAbi, metaMorphoFactoryAbi, morphoMarketV1AdapterAbi, morphoMarketV1AdapterFactoryAbi, morphoMarketV1AdapterV2Abi, morphoMarketV1AdapterV2FactoryAbi, morphoVaultV1AdapterAbi, morphoVaultV1AdapterFactoryAbi, permissionedErc20WrapperAbi, permit2Abi,
|
|
2
|
+
export { adaptiveCurveIrmAbi as blueAdaptiveCurveIrmAbi, blueAbi, blueOracleAbi, erc2612Abi, erc3643Abi, erc3643IdentityRegistryAbi, erc5267Abi, metaMorphoAbi, metaMorphoFactoryAbi, morphoMarketV1AdapterAbi, morphoMarketV1AdapterFactoryAbi, morphoMarketV1AdapterV2Abi, morphoMarketV1AdapterV2FactoryAbi, morphoVaultV1AdapterAbi, morphoVaultV1AdapterFactoryAbi, permissionedErc20WrapperAbi, permit2Abi,
|
|
3
3
|
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
|
4
4
|
preLiquidationAbi as bluePreLiquidationAbi,
|
|
5
5
|
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
|
6
6
|
preLiquidationFactoryAbi as bluePreLiquidationFactoryAbi, vaultV2Abi, vaultV2BluePublicAllocatorAbi, vaultV2FactoryAbi, whitelistControllerAggregatorV2Abi, wrappedBackedTokenAbi, wstEthAbi, } from "@morpho-org/blue-sdk-viem";
|
|
7
|
-
export { blueBuyCallbackFactoryAbi as midnightBlueBuyCallbackFactoryAbi, ecrecoverAuthorizerAbi as midnightEcrecoverAuthorizerAbi, ecrecoverRatifierAbi as midnightEcrecoverRatifierAbi, midnightAbi, midnightBundlesV2Abi, midnightEventsAbi, priceRatifierV1Abi as midnightPriceRatifierV1Abi, rateRatifierV1Abi as midnightRateRatifierV1Abi, setterRatifierAbi as midnightSetterRatifierAbi, } from "@morpho-org/midnight-sdk";
|
|
7
|
+
export { blueBuyCallbackAbi as midnightBlueBuyCallbackAbi, blueBuyCallbackFactoryAbi as midnightBlueBuyCallbackFactoryAbi, ecrecoverAuthorizerAbi as midnightEcrecoverAuthorizerAbi, ecrecoverRatifierAbi as midnightEcrecoverRatifierAbi, midnightAbi, midnightBundlesV2Abi, midnightEventsAbi, priceRatifierV1Abi as midnightPriceRatifierV1Abi, rateRatifierV1Abi as midnightRateRatifierV1Abi, setterRatifierAbi as midnightSetterRatifierAbi, } from "@morpho-org/midnight-sdk";
|
|
8
8
|
/** ABI for the VaultExitBundlesV1 periphery contract. */
|
|
9
9
|
export declare const vaultExitBundlesV1Abi: readonly [{
|
|
10
10
|
readonly type: "constructor";
|
package/lib/cjs/abis.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.blueBundlesV1Abi = exports.vaultBundlesV1Abi = exports.vaultExitBundlesV1Abi = exports.midnightSetterRatifierAbi = exports.midnightRateRatifierV1Abi = exports.midnightPriceRatifierV1Abi = exports.midnightEventsAbi = exports.midnightBundlesV2Abi = exports.midnightAbi = exports.midnightEcrecoverRatifierAbi = exports.midnightEcrecoverAuthorizerAbi = exports.midnightBlueBuyCallbackFactoryAbi = exports.wstEthAbi = exports.wrappedBackedTokenAbi = exports.whitelistControllerAggregatorV2Abi = exports.vaultV2FactoryAbi = exports.vaultV2BluePublicAllocatorAbi = exports.vaultV2Abi = exports.bluePreLiquidationFactoryAbi = exports.bluePreLiquidationAbi = exports.permit2Abi = exports.permissionedErc20WrapperAbi = exports.morphoVaultV1AdapterFactoryAbi = exports.morphoVaultV1AdapterAbi = exports.morphoMarketV1AdapterV2FactoryAbi = exports.morphoMarketV1AdapterV2Abi = exports.morphoMarketV1AdapterFactoryAbi = exports.morphoMarketV1AdapterAbi = exports.metaMorphoFactoryAbi = exports.metaMorphoAbi = exports.erc5267Abi = exports.erc2612Abi = exports.blueOracleAbi = exports.blueAbi = exports.blueAdaptiveCurveIrmAbi = exports.blueMarketParamsAbi = void 0;
|
|
3
|
+
exports.blueBundlesV1Abi = exports.vaultBundlesV1Abi = exports.vaultExitBundlesV1Abi = exports.midnightSetterRatifierAbi = exports.midnightRateRatifierV1Abi = exports.midnightPriceRatifierV1Abi = exports.midnightEventsAbi = exports.midnightBundlesV2Abi = exports.midnightAbi = exports.midnightEcrecoverRatifierAbi = exports.midnightEcrecoverAuthorizerAbi = exports.midnightBlueBuyCallbackFactoryAbi = exports.midnightBlueBuyCallbackAbi = exports.wstEthAbi = exports.wrappedBackedTokenAbi = exports.whitelistControllerAggregatorV2Abi = exports.vaultV2FactoryAbi = exports.vaultV2BluePublicAllocatorAbi = exports.vaultV2Abi = exports.bluePreLiquidationFactoryAbi = exports.bluePreLiquidationAbi = exports.permit2Abi = exports.permissionedErc20WrapperAbi = exports.morphoVaultV1AdapterFactoryAbi = exports.morphoVaultV1AdapterAbi = exports.morphoMarketV1AdapterV2FactoryAbi = exports.morphoMarketV1AdapterV2Abi = exports.morphoMarketV1AdapterFactoryAbi = exports.morphoMarketV1AdapterAbi = exports.metaMorphoFactoryAbi = exports.metaMorphoAbi = exports.erc5267Abi = exports.erc3643IdentityRegistryAbi = exports.erc3643Abi = exports.erc2612Abi = exports.blueOracleAbi = exports.blueAbi = exports.blueAdaptiveCurveIrmAbi = exports.blueMarketParamsAbi = void 0;
|
|
4
4
|
var blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
5
5
|
Object.defineProperty(exports, "blueMarketParamsAbi", { enumerable: true, get: function () { return blue_sdk_1.marketParamsAbi; } });
|
|
6
6
|
var blue_sdk_viem_1 = require("@morpho-org/blue-sdk-viem");
|
|
@@ -8,6 +8,8 @@ Object.defineProperty(exports, "blueAdaptiveCurveIrmAbi", { enumerable: true, ge
|
|
|
8
8
|
Object.defineProperty(exports, "blueAbi", { enumerable: true, get: function () { return blue_sdk_viem_1.blueAbi; } });
|
|
9
9
|
Object.defineProperty(exports, "blueOracleAbi", { enumerable: true, get: function () { return blue_sdk_viem_1.blueOracleAbi; } });
|
|
10
10
|
Object.defineProperty(exports, "erc2612Abi", { enumerable: true, get: function () { return blue_sdk_viem_1.erc2612Abi; } });
|
|
11
|
+
Object.defineProperty(exports, "erc3643Abi", { enumerable: true, get: function () { return blue_sdk_viem_1.erc3643Abi; } });
|
|
12
|
+
Object.defineProperty(exports, "erc3643IdentityRegistryAbi", { enumerable: true, get: function () { return blue_sdk_viem_1.erc3643IdentityRegistryAbi; } });
|
|
11
13
|
Object.defineProperty(exports, "erc5267Abi", { enumerable: true, get: function () { return blue_sdk_viem_1.erc5267Abi; } });
|
|
12
14
|
Object.defineProperty(exports, "metaMorphoAbi", { enumerable: true, get: function () { return blue_sdk_viem_1.metaMorphoAbi; } });
|
|
13
15
|
Object.defineProperty(exports, "metaMorphoFactoryAbi", { enumerable: true, get: function () { return blue_sdk_viem_1.metaMorphoFactoryAbi; } });
|
|
@@ -30,6 +32,7 @@ Object.defineProperty(exports, "whitelistControllerAggregatorV2Abi", { enumerabl
|
|
|
30
32
|
Object.defineProperty(exports, "wrappedBackedTokenAbi", { enumerable: true, get: function () { return blue_sdk_viem_1.wrappedBackedTokenAbi; } });
|
|
31
33
|
Object.defineProperty(exports, "wstEthAbi", { enumerable: true, get: function () { return blue_sdk_viem_1.wstEthAbi; } });
|
|
32
34
|
var midnight_sdk_1 = require("@morpho-org/midnight-sdk");
|
|
35
|
+
Object.defineProperty(exports, "midnightBlueBuyCallbackAbi", { enumerable: true, get: function () { return midnight_sdk_1.blueBuyCallbackAbi; } });
|
|
33
36
|
Object.defineProperty(exports, "midnightBlueBuyCallbackFactoryAbi", { enumerable: true, get: function () { return midnight_sdk_1.blueBuyCallbackFactoryAbi; } });
|
|
34
37
|
Object.defineProperty(exports, "midnightEcrecoverAuthorizerAbi", { enumerable: true, get: function () { return midnight_sdk_1.ecrecoverAuthorizerAbi; } });
|
|
35
38
|
Object.defineProperty(exports, "midnightEcrecoverRatifierAbi", { enumerable: true, get: function () { return midnight_sdk_1.ecrecoverRatifierAbi; } });
|
|
@@ -22,4 +22,5 @@ __exportStar(require("./supply.js"), exports);
|
|
|
22
22
|
__exportStar(require("./supplyCollateral.js"), exports);
|
|
23
23
|
__exportStar(require("./supplyCollateralBorrow.js"), exports);
|
|
24
24
|
__exportStar(require("./withdraw.js"), exports);
|
|
25
|
+
__exportStar(require("./withdrawBuyCallback.js"), exports);
|
|
25
26
|
__exportStar(require("./withdrawCollateral.js"), exports);
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { MarketParams } from "@morpho-org/blue-sdk";
|
|
2
|
+
import { type Address } from "viem";
|
|
3
|
+
import { type BlueWithdrawBuyCallbackAction, type Metadata, type Transaction } from "../../types/index.js";
|
|
4
|
+
/** Parameters for {@link blueWithdrawBuyCallback}. */
|
|
5
|
+
export interface BlueWithdrawBuyCallbackParams {
|
|
6
|
+
/** Chain and scoped Morpho Blue market. */
|
|
7
|
+
readonly market: {
|
|
8
|
+
readonly chainId: number;
|
|
9
|
+
readonly marketParams: MarketParams;
|
|
10
|
+
};
|
|
11
|
+
/** Direct Morpho Blue withdrawal arguments. */
|
|
12
|
+
readonly args: {
|
|
13
|
+
/** BlueBuyCallback whose supply position is withdrawn. */
|
|
14
|
+
readonly callbackAddress: Address;
|
|
15
|
+
/** Callback owner, who sends the transaction and receives the loan assets. */
|
|
16
|
+
readonly userAddress: Address;
|
|
17
|
+
/** Supply shares burned. */
|
|
18
|
+
readonly shares: bigint;
|
|
19
|
+
};
|
|
20
|
+
/** Optional transaction metadata suffix. */
|
|
21
|
+
readonly metadata?: Metadata;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Encodes a direct Morpho Blue `withdraw` of a BlueBuyCallback's supply shares to its owner.
|
|
25
|
+
*
|
|
26
|
+
* The call is `withdraw(marketParams, 0, shares, callbackAddress, userAddress)` on Morpho Blue, not
|
|
27
|
+
* BlueBundlesV1: the callback authorizes its owner on Blue, so the owner withdraws on its behalf
|
|
28
|
+
* directly. Use `client.morpho.blue(...).withdrawBuyCallback(...)` to check the callback, its owner,
|
|
29
|
+
* the Blue authorization and the market liquidity first.
|
|
30
|
+
*
|
|
31
|
+
* @param params - Withdrawal encoding parameters.
|
|
32
|
+
* @param params.market.chainId - Chain containing Morpho Blue.
|
|
33
|
+
* @param params.market.marketParams - Scoped Morpho Blue market parameters.
|
|
34
|
+
* @param params.args.callbackAddress - BlueBuyCallback whose supply position is withdrawn.
|
|
35
|
+
* @param params.args.userAddress - Callback owner, sender and receiver of the loan assets.
|
|
36
|
+
* @param params.args.shares - Supply shares burned.
|
|
37
|
+
* @param params.metadata - Optional transaction metadata.
|
|
38
|
+
* @returns A deep-frozen `Readonly<Transaction<BlueWithdrawBuyCallbackAction>>` whose `to` address
|
|
39
|
+
* is Morpho Blue.
|
|
40
|
+
* @throws {MarketIdMismatchError} when `marketParams.id` does not hash from its tuple fields.
|
|
41
|
+
* @throws {NegativeInputError} when `shares` is negative.
|
|
42
|
+
* @throws {NonPositiveInputError} when `shares` is zero.
|
|
43
|
+
* @throws {InputExceedsMaxError} when `shares` exceeds `uint256`.
|
|
44
|
+
* @throws {UnsupportedChainIdError} when the chain is absent from the registry.
|
|
45
|
+
* @throws {UnknownAddressError} when Morpho Blue is not registered.
|
|
46
|
+
* @example
|
|
47
|
+
* ```ts
|
|
48
|
+
* import { markets } from "@morpho-org/morpho-test";
|
|
49
|
+
* import { blueWithdrawBuyCallback } from "@morpho-org/morpho-sdk";
|
|
50
|
+
* import { zeroAddress } from "viem";
|
|
51
|
+
* import { mainnet } from "viem/chains";
|
|
52
|
+
*
|
|
53
|
+
* const tx = blueWithdrawBuyCallback({
|
|
54
|
+
* market: { chainId: mainnet.id, marketParams: markets[mainnet.id].usdc_wbtc },
|
|
55
|
+
* args: { callbackAddress: zeroAddress, userAddress: zeroAddress, shares: 1_000_000n },
|
|
56
|
+
* });
|
|
57
|
+
* // tx satisfies Readonly<Transaction<BlueWithdrawBuyCallbackAction>>
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
export declare const blueWithdrawBuyCallback: (params: BlueWithdrawBuyCallbackParams) => Readonly<Transaction<BlueWithdrawBuyCallbackAction>>;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.blueWithdrawBuyCallback = void 0;
|
|
4
|
+
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
5
|
+
const viem_1 = require("viem");
|
|
6
|
+
const abis_js_1 = require("../../abis.js");
|
|
7
|
+
const index_js_1 = require("../../helpers/index.js");
|
|
8
|
+
const validate_js_1 = require("../../helpers/validate.js");
|
|
9
|
+
const index_js_2 = require("../../types/index.js");
|
|
10
|
+
/**
|
|
11
|
+
* Encodes a direct Morpho Blue `withdraw` of a BlueBuyCallback's supply shares to its owner.
|
|
12
|
+
*
|
|
13
|
+
* The call is `withdraw(marketParams, 0, shares, callbackAddress, userAddress)` on Morpho Blue, not
|
|
14
|
+
* BlueBundlesV1: the callback authorizes its owner on Blue, so the owner withdraws on its behalf
|
|
15
|
+
* directly. Use `client.morpho.blue(...).withdrawBuyCallback(...)` to check the callback, its owner,
|
|
16
|
+
* the Blue authorization and the market liquidity first.
|
|
17
|
+
*
|
|
18
|
+
* @param params - Withdrawal encoding parameters.
|
|
19
|
+
* @param params.market.chainId - Chain containing Morpho Blue.
|
|
20
|
+
* @param params.market.marketParams - Scoped Morpho Blue market parameters.
|
|
21
|
+
* @param params.args.callbackAddress - BlueBuyCallback whose supply position is withdrawn.
|
|
22
|
+
* @param params.args.userAddress - Callback owner, sender and receiver of the loan assets.
|
|
23
|
+
* @param params.args.shares - Supply shares burned.
|
|
24
|
+
* @param params.metadata - Optional transaction metadata.
|
|
25
|
+
* @returns A deep-frozen `Readonly<Transaction<BlueWithdrawBuyCallbackAction>>` whose `to` address
|
|
26
|
+
* is Morpho Blue.
|
|
27
|
+
* @throws {MarketIdMismatchError} when `marketParams.id` does not hash from its tuple fields.
|
|
28
|
+
* @throws {NegativeInputError} when `shares` is negative.
|
|
29
|
+
* @throws {NonPositiveInputError} when `shares` is zero.
|
|
30
|
+
* @throws {InputExceedsMaxError} when `shares` exceeds `uint256`.
|
|
31
|
+
* @throws {UnsupportedChainIdError} when the chain is absent from the registry.
|
|
32
|
+
* @throws {UnknownAddressError} when Morpho Blue is not registered.
|
|
33
|
+
* @example
|
|
34
|
+
* ```ts
|
|
35
|
+
* import { markets } from "@morpho-org/morpho-test";
|
|
36
|
+
* import { blueWithdrawBuyCallback } from "@morpho-org/morpho-sdk";
|
|
37
|
+
* import { zeroAddress } from "viem";
|
|
38
|
+
* import { mainnet } from "viem/chains";
|
|
39
|
+
*
|
|
40
|
+
* const tx = blueWithdrawBuyCallback({
|
|
41
|
+
* market: { chainId: mainnet.id, marketParams: markets[mainnet.id].usdc_wbtc },
|
|
42
|
+
* args: { callbackAddress: zeroAddress, userAddress: zeroAddress, shares: 1_000_000n },
|
|
43
|
+
* });
|
|
44
|
+
* // tx satisfies Readonly<Transaction<BlueWithdrawBuyCallbackAction>>
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
const blueWithdrawBuyCallback = (params) => {
|
|
48
|
+
const { chainId, marketParams } = params.market;
|
|
49
|
+
const { callbackAddress, userAddress, shares } = params.args;
|
|
50
|
+
(0, validate_js_1.validateMarketParamsId)(marketParams);
|
|
51
|
+
(0, validate_js_1.validateUint256Field)("shares", shares);
|
|
52
|
+
if (shares === 0n)
|
|
53
|
+
throw new index_js_2.NonPositiveInputError("shares", shares);
|
|
54
|
+
let tx = {
|
|
55
|
+
to: (0, morpho_ts_1.getChainAddress)(chainId, "blue"),
|
|
56
|
+
value: 0n,
|
|
57
|
+
data: (0, viem_1.encodeFunctionData)({
|
|
58
|
+
abi: abis_js_1.blueAbi,
|
|
59
|
+
functionName: "withdraw",
|
|
60
|
+
args: [marketParams, 0n, shares, callbackAddress, userAddress],
|
|
61
|
+
}),
|
|
62
|
+
};
|
|
63
|
+
if (params.metadata) {
|
|
64
|
+
tx = (0, index_js_1.addTransactionMetadata)(tx, params.metadata);
|
|
65
|
+
}
|
|
66
|
+
return (0, morpho_ts_1.deepFreeze)({
|
|
67
|
+
...tx,
|
|
68
|
+
action: {
|
|
69
|
+
type: "blueWithdrawBuyCallback",
|
|
70
|
+
args: {
|
|
71
|
+
market: marketParams.id,
|
|
72
|
+
shares,
|
|
73
|
+
onBehalf: callbackAddress,
|
|
74
|
+
receiver: userAddress,
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
};
|
|
79
|
+
exports.blueWithdrawBuyCallback = blueWithdrawBuyCallback;
|
|
@@ -6,6 +6,7 @@ export type BundlesTokenRequirementsState = {
|
|
|
6
6
|
/** Current allowance of the funding token for `spender`. */
|
|
7
7
|
readonly allowance: bigint;
|
|
8
8
|
} | {
|
|
9
|
+
/** @deprecated The SDK no longer requests Permit2 funding; use ERC-2612 permits or ERC-20 approvals. */
|
|
9
10
|
readonly type: "permit2SignatureTransfer";
|
|
10
11
|
readonly permit2Allowance: bigint;
|
|
11
12
|
readonly permit2Nonce: bigint;
|
|
@@ -51,6 +51,9 @@ interface EncodeErc20PermitParams {
|
|
|
51
51
|
* @throws {MalformedTokenMetadataError} when the token's `eip712Domain()` or
|
|
52
52
|
* `bytes32` `name`/`symbol` retry returns non-empty data that does not decode, or when the
|
|
53
53
|
* deployless query reports malformed `name()`/`symbol()`/`eip712Domain()` returndata (no fallback).
|
|
54
|
+
* @throws {InvalidPermitDomainChainIdError} when the EIP-5267 domain names another chain.
|
|
55
|
+
* @throws {InvalidPermitDomainVerifyingContractError} when the EIP-5267 domain names another token.
|
|
56
|
+
* @throws {UnsupportedPermitDomainExtensionsError} when the EIP-5267 domain has extensions.
|
|
54
57
|
* @throws {MissingPermitDomainNameError} when the token exposes neither `name()` nor
|
|
55
58
|
* `eip712Domain()`, so its permit domain is unknown.
|
|
56
59
|
* @throws {viem.BaseError} when the `eth_chainId` request or a token metadata read fails at the
|
|
@@ -67,7 +70,7 @@ interface EncodeErc20PermitParams {
|
|
|
67
70
|
*
|
|
68
71
|
* const client = createWalletClient({ chain: mainnet, transport: http() });
|
|
69
72
|
* const requirement = await encodeErc20Permit(client, {
|
|
70
|
-
* token: USDC, // Must implement standard ERC-2612. DAI
|
|
73
|
+
* token: USDC, // Must implement standard ERC-2612. DAI falls back to a direct ERC-20 approval in requirement helpers.
|
|
71
74
|
* owner,
|
|
72
75
|
* spender: blueBundlesV1,
|
|
73
76
|
* amount: 1_000_000n,
|
|
@@ -44,6 +44,9 @@ const validateClientChainId_js_1 = require("../validateClientChainId.js");
|
|
|
44
44
|
* @throws {MalformedTokenMetadataError} when the token's `eip712Domain()` or
|
|
45
45
|
* `bytes32` `name`/`symbol` retry returns non-empty data that does not decode, or when the
|
|
46
46
|
* deployless query reports malformed `name()`/`symbol()`/`eip712Domain()` returndata (no fallback).
|
|
47
|
+
* @throws {InvalidPermitDomainChainIdError} when the EIP-5267 domain names another chain.
|
|
48
|
+
* @throws {InvalidPermitDomainVerifyingContractError} when the EIP-5267 domain names another token.
|
|
49
|
+
* @throws {UnsupportedPermitDomainExtensionsError} when the EIP-5267 domain has extensions.
|
|
47
50
|
* @throws {MissingPermitDomainNameError} when the token exposes neither `name()` nor
|
|
48
51
|
* `eip712Domain()`, so its permit domain is unknown.
|
|
49
52
|
* @throws {viem.BaseError} when the `eth_chainId` request or a token metadata read fails at the
|
|
@@ -60,7 +63,7 @@ const validateClientChainId_js_1 = require("../validateClientChainId.js");
|
|
|
60
63
|
*
|
|
61
64
|
* const client = createWalletClient({ chain: mainnet, transport: http() });
|
|
62
65
|
* const requirement = await encodeErc20Permit(client, {
|
|
63
|
-
* token: USDC, // Must implement standard ERC-2612. DAI
|
|
66
|
+
* token: USDC, // Must implement standard ERC-2612. DAI falls back to a direct ERC-20 approval in requirement helpers.
|
|
64
67
|
* owner,
|
|
65
68
|
* spender: blueBundlesV1,
|
|
66
69
|
* amount: 1_000_000n,
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import type { Address } from "@morpho-org/blue-sdk";
|
|
2
2
|
import { type Permit2SignatureTransferRequirementSignature, type Requirement } from "../../../types/index.js";
|
|
3
|
-
/**
|
|
3
|
+
/**
|
|
4
|
+
* Parameters for {@link encodeErc20Permit2SignatureTransfer}.
|
|
5
|
+
* @deprecated The SDK no longer requests Permit2 funding; use ERC-2612 permits or ERC-20 approvals.
|
|
6
|
+
*/
|
|
4
7
|
export interface EncodeErc20Permit2SignatureTransferParams {
|
|
5
8
|
/** ERC-20 token pulled through Permit2. */
|
|
6
9
|
readonly token: Address;
|
|
@@ -62,5 +65,6 @@ export interface EncodeErc20Permit2SignatureTransferParams {
|
|
|
62
65
|
* });
|
|
63
66
|
* // requirement satisfies Requirement<Permit2SignatureTransferRequirementSignature>
|
|
64
67
|
* ```
|
|
68
|
+
* @deprecated The SDK no longer requests Permit2 funding; use ERC-2612 permits or ERC-20 approvals.
|
|
65
69
|
*/
|
|
66
70
|
export declare const encodeErc20Permit2SignatureTransfer: (params: EncodeErc20Permit2SignatureTransferParams) => Requirement<Permit2SignatureTransferRequirementSignature>;
|
|
@@ -53,6 +53,7 @@ const index_js_1 = require("../../../types/index.js");
|
|
|
53
53
|
* });
|
|
54
54
|
* // requirement satisfies Requirement<Permit2SignatureTransferRequirementSignature>
|
|
55
55
|
* ```
|
|
56
|
+
* @deprecated The SDK no longer requests Permit2 funding; use ERC-2612 permits or ERC-20 approvals.
|
|
56
57
|
*/
|
|
57
58
|
const encodeErc20Permit2SignatureTransfer = (params) => {
|
|
58
59
|
const { token, spender, amount, chainId, nonce, deadline } = params;
|
package/lib/cjs/blue/abis.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { marketParamsAbi } from "@morpho-org/blue-sdk";
|
|
2
|
-
export { adaptiveCurveIrmAbi, blueAbi, blueOracleAbi, erc2612Abi, erc5267Abi, metaMorphoAbi, metaMorphoFactoryAbi, morphoMarketV1AdapterAbi, morphoMarketV1AdapterFactoryAbi, morphoMarketV1AdapterV2Abi, morphoMarketV1AdapterV2FactoryAbi, morphoVaultV1AdapterAbi, morphoVaultV1AdapterFactoryAbi, permissionedErc20WrapperAbi, permit2Abi,
|
|
2
|
+
export { adaptiveCurveIrmAbi, blueAbi, blueOracleAbi, erc2612Abi, erc3643Abi, erc3643IdentityRegistryAbi, erc5267Abi, metaMorphoAbi, metaMorphoFactoryAbi, morphoMarketV1AdapterAbi, morphoMarketV1AdapterFactoryAbi, morphoMarketV1AdapterV2Abi, morphoMarketV1AdapterV2FactoryAbi, morphoVaultV1AdapterAbi, morphoVaultV1AdapterFactoryAbi, permissionedErc20WrapperAbi, permit2Abi,
|
|
3
3
|
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
|
4
4
|
preLiquidationAbi,
|
|
5
5
|
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
package/lib/cjs/blue/abis.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.wstEthAbi = exports.wrappedBackedTokenAbi = exports.whitelistControllerAggregatorV2Abi = exports.vaultV2FactoryAbi = exports.vaultV2BluePublicAllocatorAbi = exports.vaultV2Abi = exports.preLiquidationFactoryAbi = exports.preLiquidationAbi = exports.permit2Abi = exports.permissionedErc20WrapperAbi = exports.morphoVaultV1AdapterFactoryAbi = exports.morphoVaultV1AdapterAbi = exports.morphoMarketV1AdapterV2FactoryAbi = exports.morphoMarketV1AdapterV2Abi = exports.morphoMarketV1AdapterFactoryAbi = exports.morphoMarketV1AdapterAbi = exports.metaMorphoFactoryAbi = exports.metaMorphoAbi = exports.erc5267Abi = exports.erc2612Abi = exports.blueOracleAbi = exports.blueAbi = exports.adaptiveCurveIrmAbi = exports.marketParamsAbi = void 0;
|
|
3
|
+
exports.wstEthAbi = exports.wrappedBackedTokenAbi = exports.whitelistControllerAggregatorV2Abi = exports.vaultV2FactoryAbi = exports.vaultV2BluePublicAllocatorAbi = exports.vaultV2Abi = exports.preLiquidationFactoryAbi = exports.preLiquidationAbi = exports.permit2Abi = exports.permissionedErc20WrapperAbi = exports.morphoVaultV1AdapterFactoryAbi = exports.morphoVaultV1AdapterAbi = exports.morphoMarketV1AdapterV2FactoryAbi = exports.morphoMarketV1AdapterV2Abi = exports.morphoMarketV1AdapterFactoryAbi = exports.morphoMarketV1AdapterAbi = exports.metaMorphoFactoryAbi = exports.metaMorphoAbi = exports.erc5267Abi = exports.erc3643IdentityRegistryAbi = exports.erc3643Abi = exports.erc2612Abi = exports.blueOracleAbi = exports.blueAbi = exports.adaptiveCurveIrmAbi = exports.marketParamsAbi = void 0;
|
|
4
4
|
var blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
5
5
|
Object.defineProperty(exports, "marketParamsAbi", { enumerable: true, get: function () { return blue_sdk_1.marketParamsAbi; } });
|
|
6
6
|
var blue_sdk_viem_1 = require("@morpho-org/blue-sdk-viem");
|
|
@@ -8,6 +8,8 @@ Object.defineProperty(exports, "adaptiveCurveIrmAbi", { enumerable: true, get: f
|
|
|
8
8
|
Object.defineProperty(exports, "blueAbi", { enumerable: true, get: function () { return blue_sdk_viem_1.blueAbi; } });
|
|
9
9
|
Object.defineProperty(exports, "blueOracleAbi", { enumerable: true, get: function () { return blue_sdk_viem_1.blueOracleAbi; } });
|
|
10
10
|
Object.defineProperty(exports, "erc2612Abi", { enumerable: true, get: function () { return blue_sdk_viem_1.erc2612Abi; } });
|
|
11
|
+
Object.defineProperty(exports, "erc3643Abi", { enumerable: true, get: function () { return blue_sdk_viem_1.erc3643Abi; } });
|
|
12
|
+
Object.defineProperty(exports, "erc3643IdentityRegistryAbi", { enumerable: true, get: function () { return blue_sdk_viem_1.erc3643IdentityRegistryAbi; } });
|
|
11
13
|
Object.defineProperty(exports, "erc5267Abi", { enumerable: true, get: function () { return blue_sdk_viem_1.erc5267Abi; } });
|
|
12
14
|
Object.defineProperty(exports, "metaMorphoAbi", { enumerable: true, get: function () { return blue_sdk_viem_1.metaMorphoAbi; } });
|
|
13
15
|
Object.defineProperty(exports, "metaMorphoFactoryAbi", { enumerable: true, get: function () { return blue_sdk_viem_1.metaMorphoFactoryAbi; } });
|
|
@@ -12,7 +12,7 @@ import type { Metadata, MorphoClientType } from "../types/index.js";
|
|
|
12
12
|
* @param _options.metadata - Optional analytics metadata applied to every transaction the
|
|
13
13
|
* `morpho` namespace builds.
|
|
14
14
|
* @param _options.supportSignature - Whether the integrator can collect EIP-712 signatures for
|
|
15
|
-
* ERC-2612
|
|
15
|
+
* ERC-2612 and Morpho authorization.
|
|
16
16
|
* Defaults to `false` (standalone approvals and authorization calls only).
|
|
17
17
|
* @param _options.supportDeployless - Whether entity fetchers may use deployless multicall.
|
|
18
18
|
* @returns A viem extension function — `client.extend(morphoViemExtension(...))` adds
|
|
@@ -49,7 +49,7 @@ function createMorphoNamespace(viemClient, options) {
|
|
|
49
49
|
* @param _options.metadata - Optional analytics metadata applied to every transaction the
|
|
50
50
|
* `morpho` namespace builds.
|
|
51
51
|
* @param _options.supportSignature - Whether the integrator can collect EIP-712 signatures for
|
|
52
|
-
* ERC-2612
|
|
52
|
+
* ERC-2612 and Morpho authorization.
|
|
53
53
|
* Defaults to `false` (standalone approvals and authorization calls only).
|
|
54
54
|
* @param _options.supportDeployless - Whether entity fetchers may use deployless multicall.
|
|
55
55
|
* @returns A viem extension function — `client.extend(morphoViemExtension(...))` adds
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type AccrualPosition, type Market, type MarketParams } from "@morpho-org/blue-sdk";
|
|
2
2
|
import { type Address } from "viem";
|
|
3
3
|
import type { FetchParameters } from "../../types/data.js";
|
|
4
|
-
import { type ActionOutput, type ActionRequirement, type AssetsOrSharesArgs, type BlueBorrowAction, type BlueRefinanceAction, type BlueRepayAction, type BlueRepayWithdrawCollateralAction, type BlueSupplyAction, type BlueSupplyCollateralAction, type BlueSupplyCollateralBorrowAction, type BlueWithdrawAction, type BlueWithdrawCollateralAction, type MorphoClientType, type RequirementSignature, type VaultV2BluePublicAllocatorOptions, type VaultV2BlueReallocation } from "../../types/index.js";
|
|
4
|
+
import { type ActionOutput, type ActionRequirement, type AssetsOrSharesArgs, type BlueBorrowAction, type BlueRefinanceAction, type BlueRepayAction, type BlueRepayWithdrawCollateralAction, type BlueSupplyAction, type BlueSupplyCollateralAction, type BlueSupplyCollateralBorrowAction, type BlueWithdrawAction, type BlueWithdrawBuyCallbackAction, type BlueWithdrawCollateralAction, type MorphoClientType, type RequirementSignature, type VaultV2BluePublicAllocatorOptions, type VaultV2BlueReallocation } from "../../types/index.js";
|
|
5
5
|
import { VaultV2BlueReallocationData } from "../vaultV2BlueReallocationData.js";
|
|
6
6
|
type VaultV2BlueReallocationsParams = {
|
|
7
7
|
readonly reallocationData: VaultV2BlueReallocationData;
|
|
@@ -18,12 +18,15 @@ type VaultV2BlueReallocationsParams = {
|
|
|
18
18
|
};
|
|
19
19
|
/** Options for resolving token-backed BlueBundlesV1 approval or signature prerequisites. */
|
|
20
20
|
export interface BlueTokenRequirementsParams {
|
|
21
|
-
/** Prefer ERC-2612 when the funded token exposes a compatible nonce. */
|
|
21
|
+
/** Prefer ERC-2612 when the funded token exposes a compatible nonce; defaults to true when signatures are supported. */
|
|
22
22
|
readonly useSimplePermit?: boolean;
|
|
23
|
-
/**
|
|
23
|
+
/** @deprecated Ignored. The SDK no longer requests Permit2 funding; use ERC-2612 permits or ERC-20 approvals. */
|
|
24
24
|
readonly permit2Nonce?: bigint;
|
|
25
25
|
}
|
|
26
|
-
/**
|
|
26
|
+
/**
|
|
27
|
+
* Action surface for Morpho Blue reads and writes; writes route through BlueBundlesV1, except
|
|
28
|
+
* `withdrawBuyCallback`, which calls Morpho Blue directly.
|
|
29
|
+
*/
|
|
27
30
|
export interface BlueActions {
|
|
28
31
|
/**
|
|
29
32
|
* Fetches the latest market data with accrued interest.
|
|
@@ -92,8 +95,6 @@ export interface BlueActions {
|
|
|
92
95
|
* @throws {NativeAmountOnNonWNativeAssetError} when native funding targets another token.
|
|
93
96
|
* @throws {InputExceedsMaxError} when the referral fee is at least WAD.
|
|
94
97
|
* @throws {ReferralFeeRecipientMissingError} when a positive fee has no recipient.
|
|
95
|
-
* @throws {NoUnusedPermit2NonceError} from `getRequirements()` when every Permit2 nonce for the owner is consumed and none was passed explicitly.
|
|
96
|
-
* @throws {Permit2SignatureTransferNonceAlreadyUsedError} from `getRequirements()` when the explicit Permit2 nonce is consumed.
|
|
97
98
|
* @throws {AmbiguousRequirementSignaturesError} from `buildTx()` when multiple token signatures are supplied.
|
|
98
99
|
* @throws {UnexpectedRequirementSignatureError} from `buildTx()` when an unsupported signature is supplied.
|
|
99
100
|
* @throws {DepositOwnerMismatchError} from `buildTx()` when the signed owner differs from `userAddress`.
|
|
@@ -141,10 +142,9 @@ export interface BlueActions {
|
|
|
141
142
|
/**
|
|
142
143
|
* Prepares a direct BlueBundlesV1 loan-asset supply.
|
|
143
144
|
*
|
|
144
|
-
* `getRequirements()` first checks that BlueBundlesV1
|
|
145
|
-
*
|
|
146
|
-
*
|
|
147
|
-
* BlueBundlesV1 as spender; Permit2 keeps its ERC-20 approval on canonical Permit2. Native
|
|
145
|
+
* `getRequirements()` first checks that BlueBundlesV1 and Blue hold code, then
|
|
146
|
+
* reads the loan-token allowance and selected ERC-2612 nonce state. Direct approvals and
|
|
147
|
+
* ERC-2612 name BlueBundlesV1 as spender. Native
|
|
148
148
|
* funding is exclusive and skips token requirements (the code check still runs).
|
|
149
149
|
* The referral fee is deducted from the gross `assets` supplied. This route exposes no
|
|
150
150
|
* share-price bound or `slippageTolerance`.
|
|
@@ -163,14 +163,12 @@ export interface BlueActions {
|
|
|
163
163
|
* `getRequirements()` when the RPC reports another chain via `eth_chainId`.
|
|
164
164
|
* @throws {ExpiredDeadlineError} when the deadline is not in the future at creation or requirement resolution.
|
|
165
165
|
* @throws {NonPositiveInputError} when `assets` is not positive.
|
|
166
|
-
* @throws {NegativeInputError} when native funding or the referral fee is negative
|
|
166
|
+
* @throws {NegativeInputError} when native funding or the referral fee is negative.
|
|
167
167
|
* @throws {NativeFundingAmountMismatchError} when native funding is partial or mixed.
|
|
168
168
|
* @throws {ChainWNativeMissingError} when native funding is requested on a chain without wNative.
|
|
169
169
|
* @throws {NativeAmountOnNonWNativeAssetError} when native funding targets another token.
|
|
170
|
-
* @throws {InputExceedsMaxError} when `assets` or `deadline` exceeds `uint256`, when the referral fee is at least WAD
|
|
170
|
+
* @throws {InputExceedsMaxError} when `assets` or `deadline` exceeds `uint256`, when the referral fee is at least WAD.
|
|
171
171
|
* @throws {ReferralFeeRecipientMissingError} when a positive fee has no recipient.
|
|
172
|
-
* @throws {NoUnusedPermit2NonceError} from `getRequirements()` when every Permit2 nonce for the owner is consumed and none was passed explicitly.
|
|
173
|
-
* @throws {Permit2SignatureTransferNonceAlreadyUsedError} from `getRequirements()` when the explicit Permit2 nonce is consumed.
|
|
174
172
|
* @throws {AmbiguousRequirementSignaturesError} from `buildTx()` when multiple token signatures are supplied.
|
|
175
173
|
* @throws {UnexpectedRequirementSignatureError} from `buildTx()` when the route cannot consume a supplied signature.
|
|
176
174
|
* @throws {DepositOwnerMismatchError} from `buildTx()` when the signed owner differs from `userAddress`.
|
|
@@ -314,6 +312,76 @@ export interface BlueActions {
|
|
|
314
312
|
readonly referralFeePct?: bigint;
|
|
315
313
|
readonly referralFeeRecipient?: Address;
|
|
316
314
|
} & AssetsOrSharesArgs) => ActionOutput<BlueWithdrawAction, readonly RequirementSignature[], undefined>;
|
|
315
|
+
/**
|
|
316
|
+
* Prepares a direct Morpho Blue withdrawal of a BlueBuyCallback's whole supply position to its
|
|
317
|
+
* owner.
|
|
318
|
+
*
|
|
319
|
+
* A BlueBuyCallback parks a maker's Midnight buy-offer funds as Blue supply owned by the
|
|
320
|
+
* callback. After the offer is cancelled or expires, its owner recovers them with
|
|
321
|
+
* `withdraw(marketParams, 0, supplyShares, callbackAddress, userAddress)` sent straight to Morpho
|
|
322
|
+
* Blue: BlueBundlesV1 cannot act for the callback. The callback's constructor authorizes its
|
|
323
|
+
* owner on Blue, so no requirement is returned.
|
|
324
|
+
*
|
|
325
|
+
* The handle checks the snapshot synchronously: it must be the callback's position on this
|
|
326
|
+
* market, hold supply shares, and the market's liquidity must cover their assets.
|
|
327
|
+
* `getRequirements()` then reads the chain and throws unless the registered
|
|
328
|
+
* `midnightBlueBuyCallbackFactory` created the callback, its `OWNER()` is `userAddress`, and Blue
|
|
329
|
+
* still authorizes `userAddress` for the callback. Await it before submitting the transaction.
|
|
330
|
+
*
|
|
331
|
+
* @param params.userAddress - Callback owner, who sends the transaction and receives the assets.
|
|
332
|
+
* @param params.callbackAddress - BlueBuyCallback whose supply position is withdrawn.
|
|
333
|
+
* @param params.positionData - Fresh snapshot of the callback's position on this market, for
|
|
334
|
+
* example from `getPositionData(callbackAddress)`. Every supply share in it is withdrawn.
|
|
335
|
+
* @returns Lazy owner and authorization checks with no requirements, and a synchronous
|
|
336
|
+
* deep-frozen transaction targeting Morpho Blue.
|
|
337
|
+
* @throws {ChainIdMismatchError} when the client targets another chain, or from
|
|
338
|
+
* `getRequirements()` when the RPC reports another chain via `eth_chainId`.
|
|
339
|
+
* @throws {viem.InvalidAddressError} when `callbackAddress` is malformed.
|
|
340
|
+
* @throws {MissingAccrualPositionError} when no position snapshot is provided.
|
|
341
|
+
* @throws {MarketIdMismatchError} when `positionData` belongs to another market.
|
|
342
|
+
* @throws {AccrualPositionUserMismatchError} when `positionData` belongs to another account than
|
|
343
|
+
* `callbackAddress`.
|
|
344
|
+
* @throws {EmptyBlueSupplyPositionError} when the callback holds no supply shares.
|
|
345
|
+
* @throws {InsufficientBlueLiquidityError} when the position's assets exceed market liquidity.
|
|
346
|
+
* @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
|
|
347
|
+
* @throws {UnknownAddressError} when Morpho Blue or `midnightBlueBuyCallbackFactory` is not
|
|
348
|
+
* registered.
|
|
349
|
+
* @throws {MissingContractCodeError} from `getRequirements()` when Morpho Blue or the factory has
|
|
350
|
+
* no code at its registered address.
|
|
351
|
+
* @throws {NotBlueBuyCallbackError} from `getRequirements()` when the factory did not create
|
|
352
|
+
* `callbackAddress`.
|
|
353
|
+
* @throws {BlueBuyCallbackOwnerMismatchError} from `getRequirements()` when the callback's
|
|
354
|
+
* `OWNER()` is not `userAddress`.
|
|
355
|
+
* @throws {BlueBuyCallbackUnauthorizedError} from `getRequirements()` when Blue does not
|
|
356
|
+
* authorize `userAddress` for the callback.
|
|
357
|
+
* @throws {viem.BaseError} from `getRequirements()` when a read fails.
|
|
358
|
+
* @example
|
|
359
|
+
* ```ts
|
|
360
|
+
* import { markets } from "@morpho-org/morpho-test";
|
|
361
|
+
* import { createPublicClient, http, zeroAddress } from "viem";
|
|
362
|
+
* import { mainnet } from "viem/chains";
|
|
363
|
+
* import { morphoViemExtension } from "@morpho-org/morpho-sdk";
|
|
364
|
+
*
|
|
365
|
+
* const userAddress = zeroAddress;
|
|
366
|
+
* const callbackAddress = zeroAddress;
|
|
367
|
+
* const client = createPublicClient({ chain: mainnet, transport: http() })
|
|
368
|
+
* .extend(morphoViemExtension());
|
|
369
|
+
* const market = client.morpho.blue(markets[mainnet.id].usdc_wbtc, mainnet.id);
|
|
370
|
+
* const action = market.withdrawBuyCallback({
|
|
371
|
+
* userAddress,
|
|
372
|
+
* callbackAddress,
|
|
373
|
+
* positionData: await market.getPositionData(callbackAddress),
|
|
374
|
+
* });
|
|
375
|
+
* await action.getRequirements(); // throws unless userAddress owns the callback
|
|
376
|
+
* const tx = action.buildTx();
|
|
377
|
+
* // tx satisfies Readonly<Transaction<BlueWithdrawBuyCallbackAction>>
|
|
378
|
+
* ```
|
|
379
|
+
*/
|
|
380
|
+
withdrawBuyCallback: (params: {
|
|
381
|
+
readonly userAddress: Address;
|
|
382
|
+
readonly callbackAddress: Address;
|
|
383
|
+
readonly positionData: AccrualPosition;
|
|
384
|
+
}) => ActionOutput<BlueWithdrawBuyCallbackAction, undefined, undefined>;
|
|
317
385
|
/**
|
|
318
386
|
* Prepares a direct BlueBundlesV1 loan-asset borrow.
|
|
319
387
|
*
|
|
@@ -427,8 +495,6 @@ export interface BlueActions {
|
|
|
427
495
|
* @throws {NativeFundingAmountMismatchError} when native funding is partial or mixed.
|
|
428
496
|
* @throws {ChainWNativeMissingError} when native funding is requested on a chain without wNative.
|
|
429
497
|
* @throws {NativeAmountOnNonWNativeAssetError} when native funding targets another token.
|
|
430
|
-
* @throws {NoUnusedPermit2NonceError} from `getRequirements()` when every Permit2 nonce for the owner is consumed and none was passed explicitly.
|
|
431
|
-
* @throws {Permit2SignatureTransferNonceAlreadyUsedError} from `getRequirements()` when the explicit Permit2 nonce is consumed.
|
|
432
498
|
* @throws {AmbiguousRequirementSignaturesError} from `buildTx()` when multiple token signatures are supplied.
|
|
433
499
|
* @throws {UnexpectedRequirementSignatureError} from `buildTx()` when an authorization signature is supplied.
|
|
434
500
|
* @throws {DepositOwnerMismatchError} from `buildTx()` when the signed owner differs from `userAddress`.
|
|
@@ -602,8 +668,6 @@ export interface BlueActions {
|
|
|
602
668
|
* @throws {NativeFundingAmountMismatchError} when native funding is partial or mixed.
|
|
603
669
|
* @throws {ChainWNativeMissingError} when native funding is requested on a chain without wNative.
|
|
604
670
|
* @throws {NativeAmountOnNonWNativeAssetError} when native funding targets another token.
|
|
605
|
-
* @throws {NoUnusedPermit2NonceError} from `getRequirements()` when every Permit2 nonce for the owner is consumed and none was passed explicitly.
|
|
606
|
-
* @throws {Permit2SignatureTransferNonceAlreadyUsedError} from `getRequirements()` when the explicit Permit2 nonce is consumed.
|
|
607
671
|
* @throws {AmbiguousRequirementSignaturesError} from `buildTx()` when multiple signatures of one kind are supplied.
|
|
608
672
|
* @throws {UnexpectedRequirementSignatureError} from `buildTx()` when an inactive leg cannot consume a supplied signature.
|
|
609
673
|
* @throws {DepositOwnerMismatchError} from `buildTx()` when a signed owner differs from `userAddress`.
|
|
@@ -709,8 +773,6 @@ export interface BlueActions {
|
|
|
709
773
|
* @throws {InconsistentReallocationPenaltyError} when one vault uses different penalties.
|
|
710
774
|
* @throws {ReallocationWithdrawalOnTargetMarketError} when a source is the target market.
|
|
711
775
|
* @throws {ReallocationLoanTokenMismatchError} when a source uses another loan token.
|
|
712
|
-
* @throws {NoUnusedPermit2NonceError} from `getRequirements()` when every Permit2 nonce for the owner is consumed and none was passed explicitly.
|
|
713
|
-
* @throws {Permit2SignatureTransferNonceAlreadyUsedError} from `getRequirements()` when the explicit Permit2 nonce is consumed.
|
|
714
776
|
* @throws {AmbiguousRequirementSignaturesError} from `buildTx()` when multiple signatures of one kind are supplied.
|
|
715
777
|
* @throws {UnexpectedRequirementSignatureError} from `buildTx()` when an inactive leg cannot consume a supplied signature.
|
|
716
778
|
* @throws {DepositOwnerMismatchError} from `buildTx()` when a signed owner differs from `userAddress`.
|
|
@@ -978,9 +1040,6 @@ export declare class MorphoBlue implements BlueActions {
|
|
|
978
1040
|
* spender/authorized operator holds code, with one `eth_getCode` per distinct address
|
|
979
1041
|
* before any other requirement read. Blue write flows probe `eth_chainId` only after a target
|
|
980
1042
|
* has no code and report a chain mismatch when the RPC serves another chain.
|
|
981
|
-
*
|
|
982
|
-
* @param params.erc20Funding - Whether the flow resolves an ERC-20 funding leg, which
|
|
983
|
-
* may name canonical Permit2 when signatures are supported.
|
|
984
1043
|
*/
|
|
985
1044
|
private assertWriteTargets;
|
|
986
1045
|
private getMaxLtv;
|
|
@@ -1022,6 +1081,12 @@ export declare class MorphoBlue implements BlueActions {
|
|
|
1022
1081
|
getRequirements: () => Promise<readonly ActionRequirement[]>;
|
|
1023
1082
|
buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<import("../../index.js").Transaction<BlueWithdrawAction>>;
|
|
1024
1083
|
};
|
|
1084
|
+
/** {@inheritDoc BlueActions.withdrawBuyCallback} */
|
|
1085
|
+
withdrawBuyCallback(params: {
|
|
1086
|
+
readonly userAddress: Address;
|
|
1087
|
+
readonly callbackAddress: Address;
|
|
1088
|
+
readonly positionData: AccrualPosition;
|
|
1089
|
+
}): ActionOutput<BlueWithdrawBuyCallbackAction, undefined, undefined>;
|
|
1025
1090
|
/** {@inheritDoc BlueActions.supplyCollateral} */
|
|
1026
1091
|
supplyCollateral(params: {
|
|
1027
1092
|
readonly userAddress: Address;
|