@morpho-org/morpho-sdk 9.3.0 → 9.4.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/README.md +3 -1
- 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/blue/abis.d.ts +1 -1
- package/lib/cjs/blue/abis.js +3 -1
- package/lib/cjs/entities/blue/blue.d.ts +81 -2
- package/lib/cjs/entities/blue/blue.js +85 -0
- package/lib/cjs/entities/requirements/getBundlesTokenRequirements.d.ts +5 -4
- package/lib/cjs/entities/requirements/getBundlesTokenRequirements.js +15 -12
- 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 +15 -1
- package/lib/cjs/types/error.d.ts +34 -0
- package/lib/cjs/types/error.js +41 -1
- 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/blue/abis.d.ts +1 -1
- package/lib/esm/blue/abis.js +1 -1
- package/lib/esm/entities/blue/blue.d.ts +81 -2
- package/lib/esm/entities/blue/blue.js +87 -2
- package/lib/esm/entities/requirements/getBundlesTokenRequirements.d.ts +5 -4
- package/lib/esm/entities/requirements/getBundlesTokenRequirements.js +15 -12
- 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 +15 -1
- package/lib/esm/types/error.d.ts +34 -0
- package/lib/esm/types/error.js +35 -0
- package/package.json +5 -5
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`,
|
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;
|
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; } });
|
|
@@ -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;
|
|
@@ -23,7 +23,10 @@ export interface BlueTokenRequirementsParams {
|
|
|
23
23
|
/** Explicit unused Permit2 SignatureTransfer unordered nonce; defaults to the lowest unused nonce. */
|
|
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.
|
|
@@ -314,6 +317,76 @@ export interface BlueActions {
|
|
|
314
317
|
readonly referralFeePct?: bigint;
|
|
315
318
|
readonly referralFeeRecipient?: Address;
|
|
316
319
|
} & AssetsOrSharesArgs) => ActionOutput<BlueWithdrawAction, readonly RequirementSignature[], undefined>;
|
|
320
|
+
/**
|
|
321
|
+
* Prepares a direct Morpho Blue withdrawal of a BlueBuyCallback's whole supply position to its
|
|
322
|
+
* owner.
|
|
323
|
+
*
|
|
324
|
+
* A BlueBuyCallback parks a maker's Midnight buy-offer funds as Blue supply owned by the
|
|
325
|
+
* callback. After the offer is cancelled or expires, its owner recovers them with
|
|
326
|
+
* `withdraw(marketParams, 0, supplyShares, callbackAddress, userAddress)` sent straight to Morpho
|
|
327
|
+
* Blue: BlueBundlesV1 cannot act for the callback. The callback's constructor authorizes its
|
|
328
|
+
* owner on Blue, so no requirement is returned.
|
|
329
|
+
*
|
|
330
|
+
* The handle checks the snapshot synchronously: it must be the callback's position on this
|
|
331
|
+
* market, hold supply shares, and the market's liquidity must cover their assets.
|
|
332
|
+
* `getRequirements()` then reads the chain and throws unless the registered
|
|
333
|
+
* `midnightBlueBuyCallbackFactory` created the callback, its `OWNER()` is `userAddress`, and Blue
|
|
334
|
+
* still authorizes `userAddress` for the callback. Await it before submitting the transaction.
|
|
335
|
+
*
|
|
336
|
+
* @param params.userAddress - Callback owner, who sends the transaction and receives the assets.
|
|
337
|
+
* @param params.callbackAddress - BlueBuyCallback whose supply position is withdrawn.
|
|
338
|
+
* @param params.positionData - Fresh snapshot of the callback's position on this market, for
|
|
339
|
+
* example from `getPositionData(callbackAddress)`. Every supply share in it is withdrawn.
|
|
340
|
+
* @returns Lazy owner and authorization checks with no requirements, and a synchronous
|
|
341
|
+
* deep-frozen transaction targeting Morpho Blue.
|
|
342
|
+
* @throws {ChainIdMismatchError} when the client targets another chain, or from
|
|
343
|
+
* `getRequirements()` when the RPC reports another chain via `eth_chainId`.
|
|
344
|
+
* @throws {viem.InvalidAddressError} when `callbackAddress` is malformed.
|
|
345
|
+
* @throws {MissingAccrualPositionError} when no position snapshot is provided.
|
|
346
|
+
* @throws {MarketIdMismatchError} when `positionData` belongs to another market.
|
|
347
|
+
* @throws {AccrualPositionUserMismatchError} when `positionData` belongs to another account than
|
|
348
|
+
* `callbackAddress`.
|
|
349
|
+
* @throws {EmptyBlueSupplyPositionError} when the callback holds no supply shares.
|
|
350
|
+
* @throws {InsufficientBlueLiquidityError} when the position's assets exceed market liquidity.
|
|
351
|
+
* @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
|
|
352
|
+
* @throws {UnknownAddressError} when Morpho Blue or `midnightBlueBuyCallbackFactory` is not
|
|
353
|
+
* registered.
|
|
354
|
+
* @throws {MissingContractCodeError} from `getRequirements()` when Morpho Blue or the factory has
|
|
355
|
+
* no code at its registered address.
|
|
356
|
+
* @throws {NotBlueBuyCallbackError} from `getRequirements()` when the factory did not create
|
|
357
|
+
* `callbackAddress`.
|
|
358
|
+
* @throws {BlueBuyCallbackOwnerMismatchError} from `getRequirements()` when the callback's
|
|
359
|
+
* `OWNER()` is not `userAddress`.
|
|
360
|
+
* @throws {BlueBuyCallbackUnauthorizedError} from `getRequirements()` when Blue does not
|
|
361
|
+
* authorize `userAddress` for the callback.
|
|
362
|
+
* @throws {viem.BaseError} from `getRequirements()` when a read fails.
|
|
363
|
+
* @example
|
|
364
|
+
* ```ts
|
|
365
|
+
* import { markets } from "@morpho-org/morpho-test";
|
|
366
|
+
* import { createPublicClient, http, zeroAddress } from "viem";
|
|
367
|
+
* import { mainnet } from "viem/chains";
|
|
368
|
+
* import { morphoViemExtension } from "@morpho-org/morpho-sdk";
|
|
369
|
+
*
|
|
370
|
+
* const userAddress = zeroAddress;
|
|
371
|
+
* const callbackAddress = zeroAddress;
|
|
372
|
+
* const client = createPublicClient({ chain: mainnet, transport: http() })
|
|
373
|
+
* .extend(morphoViemExtension());
|
|
374
|
+
* const market = client.morpho.blue(markets[mainnet.id].usdc_wbtc, mainnet.id);
|
|
375
|
+
* const action = market.withdrawBuyCallback({
|
|
376
|
+
* userAddress,
|
|
377
|
+
* callbackAddress,
|
|
378
|
+
* positionData: await market.getPositionData(callbackAddress),
|
|
379
|
+
* });
|
|
380
|
+
* await action.getRequirements(); // throws unless userAddress owns the callback
|
|
381
|
+
* const tx = action.buildTx();
|
|
382
|
+
* // tx satisfies Readonly<Transaction<BlueWithdrawBuyCallbackAction>>
|
|
383
|
+
* ```
|
|
384
|
+
*/
|
|
385
|
+
withdrawBuyCallback: (params: {
|
|
386
|
+
readonly userAddress: Address;
|
|
387
|
+
readonly callbackAddress: Address;
|
|
388
|
+
readonly positionData: AccrualPosition;
|
|
389
|
+
}) => ActionOutput<BlueWithdrawBuyCallbackAction, undefined, undefined>;
|
|
317
390
|
/**
|
|
318
391
|
* Prepares a direct BlueBundlesV1 loan-asset borrow.
|
|
319
392
|
*
|
|
@@ -1022,6 +1095,12 @@ export declare class MorphoBlue implements BlueActions {
|
|
|
1022
1095
|
getRequirements: () => Promise<readonly ActionRequirement[]>;
|
|
1023
1096
|
buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<import("../../index.js").Transaction<BlueWithdrawAction>>;
|
|
1024
1097
|
};
|
|
1098
|
+
/** {@inheritDoc BlueActions.withdrawBuyCallback} */
|
|
1099
|
+
withdrawBuyCallback(params: {
|
|
1100
|
+
readonly userAddress: Address;
|
|
1101
|
+
readonly callbackAddress: Address;
|
|
1102
|
+
readonly positionData: AccrualPosition;
|
|
1103
|
+
}): ActionOutput<BlueWithdrawBuyCallbackAction, undefined, undefined>;
|
|
1025
1104
|
/** {@inheritDoc BlueActions.supplyCollateral} */
|
|
1026
1105
|
supplyCollateral(params: {
|
|
1027
1106
|
readonly userAddress: Address;
|
|
@@ -6,6 +6,7 @@ const blue_sdk_viem_1 = require("@morpho-org/blue-sdk-viem");
|
|
|
6
6
|
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
7
7
|
const viem_1 = require("viem");
|
|
8
8
|
const actions_1 = require("viem/actions");
|
|
9
|
+
const abis_js_1 = require("../../abis.js");
|
|
9
10
|
const common_js_1 = require("../../actions/blue/common.js");
|
|
10
11
|
const index_js_1 = require("../../actions/index.js");
|
|
11
12
|
const validateClientChainId_js_1 = require("../../actions/requirements/validateClientChainId.js");
|
|
@@ -266,6 +267,90 @@ class MorphoBlue {
|
|
|
266
267
|
},
|
|
267
268
|
};
|
|
268
269
|
}
|
|
270
|
+
/** {@inheritDoc BlueActions.withdrawBuyCallback} */
|
|
271
|
+
withdrawBuyCallback(params) {
|
|
272
|
+
const { userAddress, callbackAddress, positionData } = params;
|
|
273
|
+
(0, index_js_2.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
|
|
274
|
+
if (positionData == null) {
|
|
275
|
+
throw new index_js_3.MissingAccrualPositionError(this.marketParams.id);
|
|
276
|
+
}
|
|
277
|
+
(0, index_js_2.validateAccrualPosition)({
|
|
278
|
+
positionData,
|
|
279
|
+
expectedMarketId: this.marketParams.id,
|
|
280
|
+
expectedUser: callbackAddress,
|
|
281
|
+
});
|
|
282
|
+
const shares = positionData.supplyShares;
|
|
283
|
+
if (shares === 0n) {
|
|
284
|
+
throw new index_js_3.EmptyBlueSupplyPositionError({
|
|
285
|
+
market: this.marketParams.id,
|
|
286
|
+
user: callbackAddress,
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
const assets = positionData.supplyAssets;
|
|
290
|
+
const liquidity = positionData.market.liquidity;
|
|
291
|
+
if (assets > liquidity) {
|
|
292
|
+
throw new index_js_3.InsufficientBlueLiquidityError({
|
|
293
|
+
market: this.marketParams.id,
|
|
294
|
+
assets,
|
|
295
|
+
liquidity,
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
const blue = (0, morpho_ts_1.getChainAddress)(this.chainId, "blue");
|
|
299
|
+
const factory = (0, morpho_ts_1.getChainAddress)(this.chainId, "midnightBlueBuyCallbackFactory");
|
|
300
|
+
const tx = (0, index_js_1.blueWithdrawBuyCallback)({
|
|
301
|
+
market: { chainId: this.chainId, marketParams: this.marketParams },
|
|
302
|
+
args: { callbackAddress, userAddress, shares },
|
|
303
|
+
metadata: this.client.options.metadata,
|
|
304
|
+
});
|
|
305
|
+
return {
|
|
306
|
+
getRequirements: async () => {
|
|
307
|
+
const viemClient = this.client.viemClient;
|
|
308
|
+
await (0, validateClientChainId_js_1.validateClientChainId)(viemClient, this.chainId);
|
|
309
|
+
await (0, assertContractCode_js_1.assertRegistryTargetsHaveCode)(viemClient, this.chainId, [
|
|
310
|
+
{ role: "blue", address: blue },
|
|
311
|
+
{ role: "midnightBlueBuyCallbackFactory", address: factory },
|
|
312
|
+
]);
|
|
313
|
+
// Check the factory first: OWNER() on an arbitrary address can revert or lie.
|
|
314
|
+
const isBlueBuyCallback = await (0, actions_1.readContract)(viemClient, {
|
|
315
|
+
address: factory,
|
|
316
|
+
abi: abis_js_1.midnightBlueBuyCallbackFactoryAbi,
|
|
317
|
+
functionName: "isBlueBuyCallback",
|
|
318
|
+
args: [callbackAddress],
|
|
319
|
+
});
|
|
320
|
+
if (!isBlueBuyCallback) {
|
|
321
|
+
throw new index_js_3.NotBlueBuyCallbackError(callbackAddress);
|
|
322
|
+
}
|
|
323
|
+
const [owner, isAuthorized] = await Promise.all([
|
|
324
|
+
(0, actions_1.readContract)(viemClient, {
|
|
325
|
+
address: callbackAddress,
|
|
326
|
+
abi: abis_js_1.midnightBlueBuyCallbackAbi,
|
|
327
|
+
functionName: "OWNER",
|
|
328
|
+
}),
|
|
329
|
+
(0, actions_1.readContract)(viemClient, {
|
|
330
|
+
address: blue,
|
|
331
|
+
abi: abis_js_1.blueAbi,
|
|
332
|
+
functionName: "isAuthorized",
|
|
333
|
+
args: [callbackAddress, userAddress],
|
|
334
|
+
}),
|
|
335
|
+
]);
|
|
336
|
+
if (!(0, viem_1.isAddressEqual)(owner, userAddress)) {
|
|
337
|
+
throw new index_js_3.BlueBuyCallbackOwnerMismatchError({
|
|
338
|
+
callback: callbackAddress,
|
|
339
|
+
owner,
|
|
340
|
+
userAddress,
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
if (!isAuthorized) {
|
|
344
|
+
throw new index_js_3.BlueBuyCallbackUnauthorizedError({
|
|
345
|
+
callback: callbackAddress,
|
|
346
|
+
userAddress,
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
return [];
|
|
350
|
+
},
|
|
351
|
+
buildTx: () => tx,
|
|
352
|
+
};
|
|
353
|
+
}
|
|
269
354
|
/** {@inheritDoc BlueActions.supplyCollateral} */
|
|
270
355
|
supplyCollateral(params) {
|
|
271
356
|
const { userAddress, collateralAssets, nativeAmount, deadline, referralFeePct, referralFeeRecipient, } = params;
|
|
@@ -29,10 +29,11 @@ export interface GetBundlesTokenRequirementsParams {
|
|
|
29
29
|
* Resolves direct approval, ERC-2612, or Permit2 SignatureTransfer prerequisites for
|
|
30
30
|
* a registered fixed bundles contract.
|
|
31
31
|
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
* the
|
|
32
|
+
* Returns no requirements when the direct bundles allowance covers the amount, even when
|
|
33
|
+
* signatures are supported. Otherwise reads only the state required by the selected path.
|
|
34
|
+
* Permit2 keeps the ERC-20 allowance on canonical Permit2 while the one-time signed transfer
|
|
35
|
+
* names the bundles contract as spender. The resolver picks the lowest unused unordered nonce
|
|
36
|
+
* by default; concurrent flows for the same owner should pass explicit nonces.
|
|
36
37
|
*
|
|
37
38
|
* @param viemClient - Connected viem client used for allowance and nonce reads.
|
|
38
39
|
* @param params - Token requirement parameters.
|
|
@@ -16,10 +16,11 @@ const getUnusedPermit2Nonce_js_1 = require("./getUnusedPermit2Nonce.js");
|
|
|
16
16
|
* Resolves direct approval, ERC-2612, or Permit2 SignatureTransfer prerequisites for
|
|
17
17
|
* a registered fixed bundles contract.
|
|
18
18
|
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
* the
|
|
19
|
+
* Returns no requirements when the direct bundles allowance covers the amount, even when
|
|
20
|
+
* signatures are supported. Otherwise reads only the state required by the selected path.
|
|
21
|
+
* Permit2 keeps the ERC-20 allowance on canonical Permit2 while the one-time signed transfer
|
|
22
|
+
* names the bundles contract as spender. The resolver picks the lowest unused unordered nonce
|
|
23
|
+
* by default; concurrent flows for the same owner should pass explicit nonces.
|
|
23
24
|
*
|
|
24
25
|
* @param viemClient - Connected viem client used for allowance and nonce reads.
|
|
25
26
|
* @param params - Token requirement parameters.
|
|
@@ -122,6 +123,14 @@ const getBundlesTokenRequirements = async (viemClient, params) => {
|
|
|
122
123
|
if (params.amount === 0n)
|
|
123
124
|
return [];
|
|
124
125
|
await (0, validateClientChainId_js_1.validateClientChainId)(viemClient, params.chainId);
|
|
126
|
+
const allowance = await (0, actions_1.readContract)(viemClient, {
|
|
127
|
+
abi: viem_1.erc20Abi,
|
|
128
|
+
address: params.token,
|
|
129
|
+
functionName: "allowance",
|
|
130
|
+
args: [params.owner, params.spender],
|
|
131
|
+
});
|
|
132
|
+
if (allowance >= params.amount)
|
|
133
|
+
return [];
|
|
125
134
|
const { permit2, dai } = (0, blue_sdk_1.getChainAddresses)(params.chainId);
|
|
126
135
|
if (params.supportSignature) {
|
|
127
136
|
const isDai = (0, morpho_ts_1.isDefined)(dai) && (0, viem_1.isAddressEqual)(params.token, dai);
|
|
@@ -174,7 +183,7 @@ const getBundlesTokenRequirements = async (viemClient, params) => {
|
|
|
174
183
|
});
|
|
175
184
|
}
|
|
176
185
|
const wordPosition = permit2Nonce >> 8n;
|
|
177
|
-
const [
|
|
186
|
+
const [permit2Allowance, nonceBitmap] = await Promise.all([
|
|
178
187
|
(0, actions_1.readContract)(viemClient, {
|
|
179
188
|
abi: viem_1.erc20Abi,
|
|
180
189
|
address: params.token,
|
|
@@ -198,19 +207,13 @@ const getBundlesTokenRequirements = async (viemClient, params) => {
|
|
|
198
207
|
now: timestamp,
|
|
199
208
|
state: {
|
|
200
209
|
type: "permit2SignatureTransfer",
|
|
201
|
-
permit2Allowance
|
|
210
|
+
permit2Allowance,
|
|
202
211
|
permit2Nonce,
|
|
203
212
|
nonceBitmap,
|
|
204
213
|
},
|
|
205
214
|
});
|
|
206
215
|
}
|
|
207
216
|
}
|
|
208
|
-
const allowance = await (0, actions_1.readContract)(viemClient, {
|
|
209
|
-
abi: viem_1.erc20Abi,
|
|
210
|
-
address: params.token,
|
|
211
|
-
functionName: "allowance",
|
|
212
|
-
args: [params.owner, params.spender],
|
|
213
|
-
});
|
|
214
217
|
return (0, index_js_1.resolveBundlesTokenRequirements)({
|
|
215
218
|
token: params.token,
|
|
216
219
|
spender: params.spender,
|
package/lib/cjs/errors.d.ts
CHANGED
|
@@ -4,4 +4,4 @@ UnsupportedPreLiquidationParamsError as UnsupportedBluePreLiquidationParamsError
|
|
|
4
4
|
export { getUnsupportedVaultV2Adapter as getBlueUnsupportedVaultV2Adapter, InvalidNumberError, InvalidPermitDomainChainIdError, InvalidPermitDomainVerifyingContractError, isUnknownOfFactoryError as isBlueUnknownOfFactoryError, MalformedTokenMetadataError, MarketParamsIdMismatchError as BlueMarketParamsIdMismatchError, MissingPermitDomainNameError, NonTupleReturnValueError, Permit2ExpirationOutOfRangeError, UnknownAbiFunctionError, UnnamedAbiOutputsError, UnsupportedPermitDomainExtensionsError, } from "@morpho-org/blue-sdk-viem";
|
|
5
5
|
export { ChainIdMismatchError as MidnightChainIdMismatchError, InvalidEcrecoverSignatureVError as InvalidMidnightEcrecoverSignatureVError, InvalidMarketParameterError as InvalidMidnightMarketParameterError, InvalidMidnightApiQuoteTargetError, InvalidMidnightApiResponseError, InvalidOfferGroupError as InvalidMidnightOfferGroupError, InvalidOfferParameterError as InvalidMidnightOfferParameterError, InvalidPositionAccrualStateError as InvalidMidnightPositionAccrualStateError, InvalidPositionAccrualTimestampError as InvalidMidnightPositionAccrualTimestampError, InvalidPositionLossFactorError as InvalidMidnightPositionLossFactorError, InvalidRateRatifierV1RateError as InvalidMidnightRateRatifierV1RateError, InvalidRateRatifierV1TickError as InvalidMidnightRateRatifierV1TickError, InvalidRateRatifierV1TimeError as InvalidMidnightRateRatifierV1TimeError, InvalidRatifierV1AddressError as InvalidMidnightRatifierV1AddressError, InvalidTickSpacingError as InvalidMidnightTickSpacingError, InvalidTreeError as InvalidMidnightTreeError, InvalidTreeHeightError as InvalidMidnightTreeHeightError, InvalidTypedDataSignatureError as InvalidMidnightTypedDataSignatureError, MidnightApiError, MidnightMempoolValidationError, PayloadDecodeError as MidnightPayloadDecodeError, PriceGreaterThanOneError as MidnightPriceGreaterThanOneError, RateRatifierV1BoundOverflowError as MidnightRateRatifierV1BoundOverflowError, RatifierV1TakerNotAllowedError as MidnightRatifierV1TakerNotAllowedError, SettlementFeeExceedsPriceError as MidnightSettlementFeeExceedsPriceError, TickOutOfRangeError as MidnightTickOutOfRangeError, UnknownCollateralIndexError as UnknownMidnightCollateralIndexError, } from "@morpho-org/midnight-sdk";
|
|
6
6
|
export type { ErrorClass } from "@morpho-org/morpho-ts";
|
|
7
|
-
export { _try, DivisionByZeroError, InvalidAddressError, InvalidBitLengthError, NegativeValueError, RegistryValueAlreadyRegisteredError, } from "@morpho-org/morpho-ts";
|
|
7
|
+
export { _try, DivisionByZeroError, InvalidAddressError, InvalidBitLengthError, NegativeValueError, RegistryValueAlreadyRegisteredError, RetriesExhaustedError, RetryStoppedError, } from "@morpho-org/morpho-ts";
|
package/lib/cjs/errors.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MidnightMempoolValidationError = exports.MidnightApiError = exports.InvalidMidnightTypedDataSignatureError = exports.InvalidMidnightTreeHeightError = exports.InvalidMidnightTreeError = exports.InvalidMidnightTickSpacingError = exports.InvalidMidnightRatifierV1AddressError = exports.InvalidMidnightRateRatifierV1TimeError = exports.InvalidMidnightRateRatifierV1TickError = exports.InvalidMidnightRateRatifierV1RateError = exports.InvalidMidnightPositionLossFactorError = exports.InvalidMidnightPositionAccrualTimestampError = exports.InvalidMidnightPositionAccrualStateError = exports.InvalidMidnightOfferParameterError = exports.InvalidMidnightOfferGroupError = exports.InvalidMidnightApiResponseError = exports.InvalidMidnightApiQuoteTargetError = exports.InvalidMidnightMarketParameterError = exports.InvalidMidnightEcrecoverSignatureVError = exports.MidnightChainIdMismatchError = exports.UnsupportedPermitDomainExtensionsError = exports.UnnamedAbiOutputsError = exports.UnknownAbiFunctionError = exports.Permit2ExpirationOutOfRangeError = exports.NonTupleReturnValueError = exports.MissingPermitDomainNameError = exports.BlueMarketParamsIdMismatchError = exports.MalformedTokenMetadataError = exports.isBlueUnknownOfFactoryError = exports.InvalidPermitDomainVerifyingContractError = exports.InvalidPermitDomainChainIdError = exports.InvalidNumberError = exports.getBlueUnsupportedVaultV2Adapter = exports.VaultV2Errors = exports.UnsupportedBlueVaultV2AdapterError = exports.UnsupportedBluePreLiquidationParamsError = exports.UnsupportedBlueMarketIrmError = exports.UnsupportedChainIdError = exports.UnknownBlueVaultConfigError = exports.UnknownBlueTokenPriceError = exports.UnknownBlueTokenError = exports.UnknownBlueOfFactory = exports.UnknownBlueMarketParamsError = exports.UnknownBlueMarketAllocationError = exports.UnknownBlueFactory = exports.UnknownBlueDataError = exports.UnknownAddressError = exports.InvalidBlueMarketParamsError = exports.IncompleteChainRegistryError = exports.BlueErrors = void 0;
|
|
4
|
-
exports.RegistryValueAlreadyRegisteredError = exports.NegativeValueError = exports.InvalidBitLengthError = exports.InvalidAddressError = exports.DivisionByZeroError = exports._try = exports.UnknownMidnightCollateralIndexError = exports.MidnightTickOutOfRangeError = exports.MidnightSettlementFeeExceedsPriceError = exports.MidnightRatifierV1TakerNotAllowedError = exports.MidnightRateRatifierV1BoundOverflowError = exports.MidnightPriceGreaterThanOneError = exports.MidnightPayloadDecodeError = void 0;
|
|
4
|
+
exports.RetryStoppedError = exports.RetriesExhaustedError = exports.RegistryValueAlreadyRegisteredError = exports.NegativeValueError = exports.InvalidBitLengthError = exports.InvalidAddressError = exports.DivisionByZeroError = exports._try = exports.UnknownMidnightCollateralIndexError = exports.MidnightTickOutOfRangeError = exports.MidnightSettlementFeeExceedsPriceError = exports.MidnightRatifierV1TakerNotAllowedError = exports.MidnightRateRatifierV1BoundOverflowError = exports.MidnightPriceGreaterThanOneError = exports.MidnightPayloadDecodeError = void 0;
|
|
5
5
|
var blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
6
6
|
Object.defineProperty(exports, "BlueErrors", { enumerable: true, get: function () { return blue_sdk_1.BlueErrors; } });
|
|
7
7
|
Object.defineProperty(exports, "IncompleteChainRegistryError", { enumerable: true, get: function () { return blue_sdk_1.IncompleteChainRegistryError; } });
|
|
@@ -70,3 +70,5 @@ Object.defineProperty(exports, "InvalidAddressError", { enumerable: true, get: f
|
|
|
70
70
|
Object.defineProperty(exports, "InvalidBitLengthError", { enumerable: true, get: function () { return morpho_ts_1.InvalidBitLengthError; } });
|
|
71
71
|
Object.defineProperty(exports, "NegativeValueError", { enumerable: true, get: function () { return morpho_ts_1.NegativeValueError; } });
|
|
72
72
|
Object.defineProperty(exports, "RegistryValueAlreadyRegisteredError", { enumerable: true, get: function () { return morpho_ts_1.RegistryValueAlreadyRegisteredError; } });
|
|
73
|
+
Object.defineProperty(exports, "RetriesExhaustedError", { enumerable: true, get: function () { return morpho_ts_1.RetriesExhaustedError; } });
|
|
74
|
+
Object.defineProperty(exports, "RetryStoppedError", { enumerable: true, get: function () { return morpho_ts_1.RetryStoppedError; } });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { blueBuyCallbackFactoryAbi, ecrecoverAuthorizerAbi, ecrecoverRatifierAbi, midnightAbi, midnightBundlesV2Abi, midnightEventsAbi, priceRatifierV1Abi, rateRatifierV1Abi, setterRatifierAbi, } from "@morpho-org/midnight-sdk";
|
|
1
|
+
export { blueBuyCallbackAbi, blueBuyCallbackFactoryAbi, ecrecoverAuthorizerAbi, ecrecoverRatifierAbi, midnightAbi, midnightBundlesV2Abi, midnightEventsAbi, priceRatifierV1Abi, rateRatifierV1Abi, setterRatifierAbi, } from "@morpho-org/midnight-sdk";
|
package/lib/cjs/midnight/abis.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.setterRatifierAbi = exports.rateRatifierV1Abi = exports.priceRatifierV1Abi = exports.midnightEventsAbi = exports.midnightBundlesV2Abi = exports.midnightAbi = exports.ecrecoverRatifierAbi = exports.ecrecoverAuthorizerAbi = exports.blueBuyCallbackFactoryAbi = void 0;
|
|
3
|
+
exports.setterRatifierAbi = exports.rateRatifierV1Abi = exports.priceRatifierV1Abi = exports.midnightEventsAbi = exports.midnightBundlesV2Abi = exports.midnightAbi = exports.ecrecoverRatifierAbi = exports.ecrecoverAuthorizerAbi = exports.blueBuyCallbackFactoryAbi = exports.blueBuyCallbackAbi = void 0;
|
|
4
4
|
var midnight_sdk_1 = require("@morpho-org/midnight-sdk");
|
|
5
|
+
Object.defineProperty(exports, "blueBuyCallbackAbi", { enumerable: true, get: function () { return midnight_sdk_1.blueBuyCallbackAbi; } });
|
|
5
6
|
Object.defineProperty(exports, "blueBuyCallbackFactoryAbi", { enumerable: true, get: function () { return midnight_sdk_1.blueBuyCallbackFactoryAbi; } });
|
|
6
7
|
Object.defineProperty(exports, "ecrecoverAuthorizerAbi", { enumerable: true, get: function () { return midnight_sdk_1.ecrecoverAuthorizerAbi; } });
|
|
7
8
|
Object.defineProperty(exports, "ecrecoverRatifierAbi", { enumerable: true, get: function () { return midnight_sdk_1.ecrecoverRatifierAbi; } });
|
|
@@ -282,6 +282,20 @@ export interface BlueWithdrawAction extends BaseAction<"blueWithdraw", {
|
|
|
282
282
|
readonly deadline: bigint;
|
|
283
283
|
}> {
|
|
284
284
|
}
|
|
285
|
+
/**
|
|
286
|
+
* Metadata for a direct Morpho Blue withdrawal of a BlueBuyCallback's whole supply position,
|
|
287
|
+
* sent by the callback's owner.
|
|
288
|
+
*/
|
|
289
|
+
export interface BlueWithdrawBuyCallbackAction extends BaseAction<"blueWithdrawBuyCallback", {
|
|
290
|
+
readonly market: Hex;
|
|
291
|
+
/** Supply shares burned: the callback's whole position. */
|
|
292
|
+
readonly shares: bigint;
|
|
293
|
+
/** BlueBuyCallback whose supply position is withdrawn. */
|
|
294
|
+
readonly onBehalf: Address;
|
|
295
|
+
/** Account receiving the withdrawn loan assets: the callback's owner. */
|
|
296
|
+
readonly receiver: Address;
|
|
297
|
+
}> {
|
|
298
|
+
}
|
|
285
299
|
type BlueSupplyCollateralBorrowActionArgs = {
|
|
286
300
|
readonly market: Hex;
|
|
287
301
|
readonly collateralAssets: bigint;
|
|
@@ -510,7 +524,7 @@ export interface MidnightCancelAndMakeAction extends BaseAction<"midnightCancelA
|
|
|
510
524
|
* VaultV2, Blue, and Midnight flows. The `type` tag discriminates the union so
|
|
511
525
|
* consumers can `switch` exhaustively on it.
|
|
512
526
|
*/
|
|
513
|
-
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 | MidnightTakeLendAction | MidnightTakeBorrowAction | MidnightTakeWithdrawAction | MidnightSupplyCollateralTakeBorrowAction | MidnightSupplyCollateralAction | MidnightWithdrawCollateralAction | MidnightRedeemAction | MidnightTakeRepayWithdrawCollateralAction | MidnightRepayWithdrawCollateralAction | MidnightCancelAndMakeAction;
|
|
527
|
+
export type TransactionAction = ERC20ApprovalAction | VaultV2DepositAction | VaultV2WithdrawAction | VaultV2RedeemAction | VaultV2InKindRedeemAction | VaultV2ForceWithdrawAction | VaultV2ForceRedeemAction | VaultV1DepositAction | VaultV1WithdrawAction | VaultV1RedeemAction | VaultV1InKindRedeemAction | VaultV1MigrateToV2Action | BlueSupplyAction | BlueSupplyCollateralAction | BlueBorrowAction | BlueSupplyCollateralBorrowAction | BlueRepayAction | BlueWithdrawCollateralAction | BlueRepayWithdrawCollateralAction | BlueWithdrawAction | BlueWithdrawBuyCallbackAction | BlueRefinanceAction | BlueAuthorizationAction | MidnightAuthorizationAction | MidnightTakeLendAction | MidnightTakeBorrowAction | MidnightTakeWithdrawAction | MidnightSupplyCollateralTakeBorrowAction | MidnightSupplyCollateralAction | MidnightWithdrawCollateralAction | MidnightRedeemAction | MidnightTakeRepayWithdrawCollateralAction | MidnightRepayWithdrawCollateralAction | MidnightCancelAndMakeAction;
|
|
514
528
|
/**
|
|
515
529
|
* Describes a single, immutable, deep-frozen transaction to submit on-chain:
|
|
516
530
|
* the target `to`, native `value`, encoded call `data`, and the originating
|