@morpho-org/morpho-sdk 9.3.0-next.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 +6 -4
- package/lib/cjs/abis.d.ts +2 -2
- package/lib/cjs/abis.js +4 -5
- 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 -5
- package/lib/cjs/blue/entities.d.ts +4 -4
- package/lib/cjs/blue/entities.js +1 -3
- package/lib/cjs/blue/errors.d.ts +2 -2
- package/lib/cjs/blue/errors.js +1 -5
- package/lib/cjs/blue/fetch.d.ts +2 -2
- package/lib/cjs/blue/fetch.js +1 -3
- package/lib/cjs/blue/utils.d.ts +1 -1
- package/lib/cjs/blue/utils.js +1 -2
- package/lib/cjs/entities/blue/blue.d.ts +85 -9
- package/lib/cjs/entities/blue/blue.js +85 -3
- package/lib/cjs/entities/index.d.ts +4 -4
- package/lib/cjs/entities/index.js +1 -3
- package/lib/cjs/entities/midnight/midnight.d.ts +1 -2
- package/lib/cjs/entities/midnight/midnight.js +4 -5
- package/lib/cjs/entities/requirements/getBundlesTokenRequirements.d.ts +5 -4
- package/lib/cjs/entities/requirements/getBundlesTokenRequirements.js +15 -12
- package/lib/cjs/entities/vaultV1/vaultV1.d.ts +0 -8
- package/lib/cjs/entities/vaultV1/vaultV1.js +0 -4
- package/lib/cjs/entities/vaultV2/vaultV2.d.ts +9 -37
- package/lib/cjs/entities/vaultV2/vaultV2.js +1 -36
- package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +3 -5
- package/lib/cjs/entities/vaultV2BlueReallocationData.js +3 -9
- package/lib/cjs/errors.d.ts +4 -4
- package/lib/cjs/errors.js +7 -10
- package/lib/cjs/fetch.d.ts +2 -2
- package/lib/cjs/fetch.js +1 -3
- package/lib/cjs/helpers/deadShares.d.ts +5 -4
- package/lib/cjs/helpers/deadShares.js +5 -6
- package/lib/cjs/midnight/abis.d.ts +1 -1
- package/lib/cjs/midnight/abis.js +2 -1
- package/lib/cjs/midnight/errors.d.ts +1 -2
- package/lib/cjs/midnight/errors.js +4 -5
- package/lib/cjs/types/action.d.ts +15 -1
- package/lib/cjs/types/error.d.ts +35 -6
- package/lib/cjs/types/error.js +42 -7
- package/lib/cjs/utils.d.ts +2 -2
- package/lib/cjs/utils.js +2 -4
- 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/blue/entities.d.ts +4 -4
- package/lib/esm/blue/entities.js +2 -2
- package/lib/esm/blue/errors.d.ts +2 -2
- package/lib/esm/blue/errors.js +2 -2
- package/lib/esm/blue/fetch.d.ts +2 -2
- package/lib/esm/blue/fetch.js +2 -2
- package/lib/esm/blue/utils.d.ts +1 -1
- package/lib/esm/blue/utils.js +1 -1
- package/lib/esm/entities/blue/blue.d.ts +85 -9
- package/lib/esm/entities/blue/blue.js +87 -5
- package/lib/esm/entities/index.d.ts +4 -4
- package/lib/esm/entities/index.js +2 -2
- package/lib/esm/entities/midnight/midnight.d.ts +1 -2
- package/lib/esm/entities/midnight/midnight.js +5 -6
- package/lib/esm/entities/requirements/getBundlesTokenRequirements.d.ts +5 -4
- package/lib/esm/entities/requirements/getBundlesTokenRequirements.js +15 -12
- package/lib/esm/entities/vaultV1/vaultV1.d.ts +0 -8
- package/lib/esm/entities/vaultV1/vaultV1.js +0 -4
- package/lib/esm/entities/vaultV2/vaultV2.d.ts +9 -37
- package/lib/esm/entities/vaultV2/vaultV2.js +1 -36
- package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +3 -5
- package/lib/esm/entities/vaultV2BlueReallocationData.js +3 -9
- package/lib/esm/errors.d.ts +4 -4
- package/lib/esm/errors.js +4 -4
- package/lib/esm/fetch.d.ts +2 -2
- package/lib/esm/fetch.js +2 -2
- package/lib/esm/helpers/deadShares.d.ts +5 -4
- package/lib/esm/helpers/deadShares.js +6 -7
- package/lib/esm/midnight/abis.d.ts +1 -1
- package/lib/esm/midnight/abis.js +1 -1
- package/lib/esm/midnight/errors.d.ts +1 -2
- package/lib/esm/midnight/errors.js +1 -2
- package/lib/esm/types/action.d.ts +15 -1
- package/lib/esm/types/error.d.ts +35 -6
- package/lib/esm/types/error.js +36 -6
- package/lib/esm/utils.d.ts +2 -2
- package/lib/esm/utils.js +2 -2
- package/package.json +6 -6
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { deepFreeze, getChainAddress } from "@morpho-org/morpho-ts";
|
|
2
|
+
import { encodeFunctionData } from "viem";
|
|
3
|
+
import { blueAbi } from "../../abis.js";
|
|
4
|
+
import { addTransactionMetadata } from "../../helpers/index.js";
|
|
5
|
+
import { validateMarketParamsId, validateUint256Field, } from "../../helpers/validate.js";
|
|
6
|
+
import { NonPositiveInputError, } from "../../types/index.js";
|
|
7
|
+
/**
|
|
8
|
+
* Encodes a direct Morpho Blue `withdraw` of a BlueBuyCallback's supply shares to its owner.
|
|
9
|
+
*
|
|
10
|
+
* The call is `withdraw(marketParams, 0, shares, callbackAddress, userAddress)` on Morpho Blue, not
|
|
11
|
+
* BlueBundlesV1: the callback authorizes its owner on Blue, so the owner withdraws on its behalf
|
|
12
|
+
* directly. Use `client.morpho.blue(...).withdrawBuyCallback(...)` to check the callback, its owner,
|
|
13
|
+
* the Blue authorization and the market liquidity first.
|
|
14
|
+
*
|
|
15
|
+
* @param params - Withdrawal encoding parameters.
|
|
16
|
+
* @param params.market.chainId - Chain containing Morpho Blue.
|
|
17
|
+
* @param params.market.marketParams - Scoped Morpho Blue market parameters.
|
|
18
|
+
* @param params.args.callbackAddress - BlueBuyCallback whose supply position is withdrawn.
|
|
19
|
+
* @param params.args.userAddress - Callback owner, sender and receiver of the loan assets.
|
|
20
|
+
* @param params.args.shares - Supply shares burned.
|
|
21
|
+
* @param params.metadata - Optional transaction metadata.
|
|
22
|
+
* @returns A deep-frozen `Readonly<Transaction<BlueWithdrawBuyCallbackAction>>` whose `to` address
|
|
23
|
+
* is Morpho Blue.
|
|
24
|
+
* @throws {MarketIdMismatchError} when `marketParams.id` does not hash from its tuple fields.
|
|
25
|
+
* @throws {NegativeInputError} when `shares` is negative.
|
|
26
|
+
* @throws {NonPositiveInputError} when `shares` is zero.
|
|
27
|
+
* @throws {InputExceedsMaxError} when `shares` exceeds `uint256`.
|
|
28
|
+
* @throws {UnsupportedChainIdError} when the chain is absent from the registry.
|
|
29
|
+
* @throws {UnknownAddressError} when Morpho Blue is not registered.
|
|
30
|
+
* @example
|
|
31
|
+
* ```ts
|
|
32
|
+
* import { markets } from "@morpho-org/morpho-test";
|
|
33
|
+
* import { blueWithdrawBuyCallback } from "@morpho-org/morpho-sdk";
|
|
34
|
+
* import { zeroAddress } from "viem";
|
|
35
|
+
* import { mainnet } from "viem/chains";
|
|
36
|
+
*
|
|
37
|
+
* const tx = blueWithdrawBuyCallback({
|
|
38
|
+
* market: { chainId: mainnet.id, marketParams: markets[mainnet.id].usdc_wbtc },
|
|
39
|
+
* args: { callbackAddress: zeroAddress, userAddress: zeroAddress, shares: 1_000_000n },
|
|
40
|
+
* });
|
|
41
|
+
* // tx satisfies Readonly<Transaction<BlueWithdrawBuyCallbackAction>>
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export const blueWithdrawBuyCallback = (params) => {
|
|
45
|
+
const { chainId, marketParams } = params.market;
|
|
46
|
+
const { callbackAddress, userAddress, shares } = params.args;
|
|
47
|
+
validateMarketParamsId(marketParams);
|
|
48
|
+
validateUint256Field("shares", shares);
|
|
49
|
+
if (shares === 0n)
|
|
50
|
+
throw new NonPositiveInputError("shares", shares);
|
|
51
|
+
let tx = {
|
|
52
|
+
to: getChainAddress(chainId, "blue"),
|
|
53
|
+
value: 0n,
|
|
54
|
+
data: encodeFunctionData({
|
|
55
|
+
abi: blueAbi,
|
|
56
|
+
functionName: "withdraw",
|
|
57
|
+
args: [marketParams, 0n, shares, callbackAddress, userAddress],
|
|
58
|
+
}),
|
|
59
|
+
};
|
|
60
|
+
if (params.metadata) {
|
|
61
|
+
tx = addTransactionMetadata(tx, params.metadata);
|
|
62
|
+
}
|
|
63
|
+
return deepFreeze({
|
|
64
|
+
...tx,
|
|
65
|
+
action: {
|
|
66
|
+
type: "blueWithdrawBuyCallback",
|
|
67
|
+
args: {
|
|
68
|
+
market: marketParams.id,
|
|
69
|
+
shares,
|
|
70
|
+
onBehalf: callbackAddress,
|
|
71
|
+
receiver: userAddress,
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
});
|
|
75
|
+
};
|
package/lib/esm/blue/abis.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { marketParamsAbi } from "@morpho-org/blue-sdk";
|
|
2
|
-
export { adaptiveCurveIrmAbi, blueAbi, blueOracleAbi, erc2612Abi,
|
|
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/esm/blue/abis.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { marketParamsAbi } from "@morpho-org/blue-sdk";
|
|
2
|
-
export { adaptiveCurveIrmAbi, blueAbi, blueOracleAbi, erc2612Abi,
|
|
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. */
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
export type { IAccrualPosition, IAccrualVault, IAccrualVaultV2, IAccrualVaultV2Adapter,
|
|
1
|
+
export type { IAccrualPosition, IAccrualVault, IAccrualVaultV2, IAccrualVaultV2Adapter, IAccrualVaultV2MorphoMarketV1Adapter, IAccrualVaultV2MorphoMarketV1AdapterV2, IAccrualVaultV2MorphoVaultV1Adapter, IAssetBalances, IEip5267Domain, IHolding, IMarket, IMarketParams, IPosition,
|
|
2
2
|
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
|
3
3
|
IPreLiquidationParams,
|
|
4
4
|
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
|
5
|
-
IPreLiquidationPosition, IToken, IVault, IVaultConfig, IVaultMarketAllocation, IVaultMarketConfig, IVaultToken, IVaultUser, IVaultV2, IVaultV2Adapter, IVaultV2Allocation, IVaultV2BlueMarketPublicAllocatorConfig, IVaultV2BluePublicAllocatorConfig,
|
|
6
|
-
export { AccrualPosition, AccrualVault, AccrualVaultV2,
|
|
5
|
+
IPreLiquidationPosition, IToken, IVault, IVaultConfig, IVaultMarketAllocation, IVaultMarketConfig, IVaultToken, IVaultUser, IVaultV2, IVaultV2Adapter, IVaultV2Allocation, IVaultV2BlueMarketPublicAllocatorConfig, IVaultV2BluePublicAllocatorConfig, IVaultV2MorphoMarketV1Adapter, IVaultV2MorphoMarketV1AdapterV2, IVaultV2MorphoVaultV1Adapter, PeripheralBalance, PeripheralBalanceType, } from "@morpho-org/blue-sdk";
|
|
6
|
+
export { AccrualPosition, AccrualVault, AccrualVaultV2, AccrualVaultV2MorphoMarketV1Adapter, AccrualVaultV2MorphoMarketV1AdapterV2, AccrualVaultV2MorphoVaultV1Adapter, AssetBalances, ConstantWrappedToken, Eip5267Domain, ExchangeRateWrappedToken, Holding, Market, MarketParams, Position,
|
|
7
7
|
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
|
8
8
|
PreLiquidationParams,
|
|
9
9
|
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
|
10
|
-
PreLiquidationPosition, Token, User, Vault, VaultConfig, VaultMarketAllocation, VaultMarketConfig, VaultToken, VaultUser, VaultV2, VaultV2Adapter, VaultV2BlueMarketPublicAllocatorConfig, VaultV2BluePublicAllocatorConfig,
|
|
10
|
+
PreLiquidationPosition, Token, User, Vault, VaultConfig, VaultMarketAllocation, VaultMarketConfig, VaultToken, VaultUser, VaultV2, VaultV2Adapter, VaultV2BlueMarketPublicAllocatorConfig, VaultV2BluePublicAllocatorConfig, VaultV2MorphoMarketV1Adapter, VaultV2MorphoMarketV1AdapterV2, VaultV2MorphoVaultV1Adapter, WrappedToken, } from "@morpho-org/blue-sdk";
|
package/lib/esm/blue/entities.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { AccrualPosition, AccrualVault, AccrualVaultV2,
|
|
1
|
+
export { AccrualPosition, AccrualVault, AccrualVaultV2, AccrualVaultV2MorphoMarketV1Adapter, AccrualVaultV2MorphoMarketV1AdapterV2, AccrualVaultV2MorphoVaultV1Adapter, AssetBalances, ConstantWrappedToken, Eip5267Domain, ExchangeRateWrappedToken, Holding, Market, MarketParams, Position,
|
|
2
2
|
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
|
3
3
|
PreLiquidationParams,
|
|
4
4
|
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
|
5
|
-
PreLiquidationPosition, Token, User, Vault, VaultConfig, VaultMarketAllocation, VaultMarketConfig, VaultToken, VaultUser, VaultV2, VaultV2Adapter, VaultV2BlueMarketPublicAllocatorConfig, VaultV2BluePublicAllocatorConfig,
|
|
5
|
+
PreLiquidationPosition, Token, User, Vault, VaultConfig, VaultMarketAllocation, VaultMarketConfig, VaultToken, VaultUser, VaultV2, VaultV2Adapter, VaultV2BlueMarketPublicAllocatorConfig, VaultV2BluePublicAllocatorConfig, VaultV2MorphoMarketV1Adapter, VaultV2MorphoMarketV1AdapterV2, VaultV2MorphoVaultV1Adapter, WrappedToken, } from "@morpho-org/blue-sdk";
|
package/lib/esm/blue/errors.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { BlueErrors, DivisionByZeroError, IncompleteChainRegistryError, InvalidAddressError, InvalidBitLengthError, InvalidMarketParamsError,
|
|
1
|
+
export { BlueErrors, DivisionByZeroError, IncompleteChainRegistryError, InvalidAddressError, InvalidBitLengthError, InvalidMarketParamsError, RegistryValueAlreadyRegisteredError, UnknownAddressError, UnknownDataError, UnknownFactory, UnknownMarketAllocationError, UnknownMarketParamsError, UnknownOfFactory, UnknownTokenError, UnknownTokenPriceError, UnknownVaultConfigError, UnsupportedChainIdError, UnsupportedMarketIrmError,
|
|
2
2
|
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
|
3
3
|
UnsupportedPreLiquidationParamsError, UnsupportedVaultV2AdapterError, VaultV2Errors, } from "@morpho-org/blue-sdk";
|
|
4
|
-
export { getUnsupportedVaultV2Adapter, InvalidNumberError, InvalidPermitDomainChainIdError, InvalidPermitDomainVerifyingContractError, isUnknownOfFactoryError, MalformedTokenMetadataError, MarketParamsIdMismatchError, MissingPermitDomainNameError, NonTupleReturnValueError, Permit2ExpirationOutOfRangeError, UnknownAbiFunctionError, UnnamedAbiOutputsError,
|
|
4
|
+
export { getUnsupportedVaultV2Adapter, InvalidNumberError, InvalidPermitDomainChainIdError, InvalidPermitDomainVerifyingContractError, isUnknownOfFactoryError, MalformedTokenMetadataError, MarketParamsIdMismatchError, MissingPermitDomainNameError, NonTupleReturnValueError, Permit2ExpirationOutOfRangeError, UnknownAbiFunctionError, UnnamedAbiOutputsError, UnsupportedPermitDomainExtensionsError, } from "@morpho-org/blue-sdk-viem";
|
package/lib/esm/blue/errors.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { BlueErrors, DivisionByZeroError, IncompleteChainRegistryError, InvalidAddressError, InvalidBitLengthError, InvalidMarketParamsError,
|
|
1
|
+
export { BlueErrors, DivisionByZeroError, IncompleteChainRegistryError, InvalidAddressError, InvalidBitLengthError, InvalidMarketParamsError, RegistryValueAlreadyRegisteredError, UnknownAddressError, UnknownDataError, UnknownFactory, UnknownMarketAllocationError, UnknownMarketParamsError, UnknownOfFactory, UnknownTokenError, UnknownTokenPriceError, UnknownVaultConfigError, UnsupportedChainIdError, UnsupportedMarketIrmError,
|
|
2
2
|
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
|
3
3
|
UnsupportedPreLiquidationParamsError, UnsupportedVaultV2AdapterError, VaultV2Errors, } from "@morpho-org/blue-sdk";
|
|
4
|
-
export { getUnsupportedVaultV2Adapter, InvalidNumberError, InvalidPermitDomainChainIdError, InvalidPermitDomainVerifyingContractError, isUnknownOfFactoryError, MalformedTokenMetadataError, MarketParamsIdMismatchError, MissingPermitDomainNameError, NonTupleReturnValueError, Permit2ExpirationOutOfRangeError, UnknownAbiFunctionError, UnnamedAbiOutputsError,
|
|
4
|
+
export { getUnsupportedVaultV2Adapter, InvalidNumberError, InvalidPermitDomainChainIdError, InvalidPermitDomainVerifyingContractError, isUnknownOfFactoryError, MalformedTokenMetadataError, MarketParamsIdMismatchError, MissingPermitDomainNameError, NonTupleReturnValueError, Permit2ExpirationOutOfRangeError, UnknownAbiFunctionError, UnnamedAbiOutputsError, UnsupportedPermitDomainExtensionsError, } from "@morpho-org/blue-sdk-viem";
|
package/lib/esm/blue/fetch.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { fetchAccrualPosition, fetchAccrualVault, fetchAccrualVaultV2, fetchAccrualVaultV2Adapter,
|
|
1
|
+
export { fetchAccrualPosition, fetchAccrualVault, fetchAccrualVaultV2, fetchAccrualVaultV2Adapter, fetchAccrualVaultV2MorphoMarketV1Adapter, fetchAccrualVaultV2MorphoMarketV1AdapterV2, fetchAccrualVaultV2MorphoVaultV1Adapter, fetchHolding, fetchMarket, fetchMarketParams, fetchPosition,
|
|
2
2
|
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
|
3
3
|
fetchPreLiquidationParams,
|
|
4
4
|
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
|
5
|
-
fetchPreLiquidationPosition, fetchToken, fetchUser, fetchVault, fetchVaultConfig, fetchVaultMarketAllocation, fetchVaultMarketConfig, fetchVaultUser, fetchVaultV2, fetchVaultV2Adapter, fetchVaultV2BlueMarketPublicAllocatorConfig, fetchVaultV2BluePublicAllocatorConfig, fetchVaultV2BluePublicAllocatorData,
|
|
5
|
+
fetchPreLiquidationPosition, fetchToken, fetchUser, fetchVault, fetchVaultConfig, fetchVaultMarketAllocation, fetchVaultMarketConfig, fetchVaultUser, fetchVaultV2, fetchVaultV2Adapter, fetchVaultV2BlueMarketPublicAllocatorConfig, fetchVaultV2BluePublicAllocatorConfig, fetchVaultV2BluePublicAllocatorData, fetchVaultV2MorphoMarketV1Adapter, fetchVaultV2MorphoMarketV1AdapterV2, fetchVaultV2MorphoVaultV1Adapter, } from "@morpho-org/blue-sdk-viem";
|
package/lib/esm/blue/fetch.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { fetchAccrualPosition, fetchAccrualVault, fetchAccrualVaultV2, fetchAccrualVaultV2Adapter,
|
|
1
|
+
export { fetchAccrualPosition, fetchAccrualVault, fetchAccrualVaultV2, fetchAccrualVaultV2Adapter, fetchAccrualVaultV2MorphoMarketV1Adapter, fetchAccrualVaultV2MorphoMarketV1AdapterV2, fetchAccrualVaultV2MorphoVaultV1Adapter, fetchHolding, fetchMarket, fetchMarketParams, fetchPosition,
|
|
2
2
|
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
|
3
3
|
fetchPreLiquidationParams,
|
|
4
4
|
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
|
5
|
-
fetchPreLiquidationPosition, fetchToken, fetchUser, fetchVault, fetchVaultConfig, fetchVaultMarketAllocation, fetchVaultMarketConfig, fetchVaultUser, fetchVaultV2, fetchVaultV2Adapter, fetchVaultV2BlueMarketPublicAllocatorConfig, fetchVaultV2BluePublicAllocatorConfig, fetchVaultV2BluePublicAllocatorData,
|
|
5
|
+
fetchPreLiquidationPosition, fetchToken, fetchUser, fetchVault, fetchVaultConfig, fetchVaultMarketAllocation, fetchVaultMarketConfig, fetchVaultUser, fetchVaultV2, fetchVaultV2Adapter, fetchVaultV2BlueMarketPublicAllocatorConfig, fetchVaultV2BluePublicAllocatorConfig, fetchVaultV2BluePublicAllocatorData, fetchVaultV2MorphoMarketV1Adapter, fetchVaultV2MorphoMarketV1AdapterV2, fetchVaultV2MorphoVaultV1Adapter, } from "@morpho-org/blue-sdk-viem";
|
package/lib/esm/blue/utils.d.ts
CHANGED
|
@@ -3,5 +3,5 @@ export { AdaptiveCurveIrmLib, CapacityLimitReason,
|
|
|
3
3
|
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
|
4
4
|
defaultPreLiquidationParamsRegistry,
|
|
5
5
|
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
|
6
|
-
getDefaultPreLiquidationParams, MarketUtils, MathLib, SharesMath, VaultUtils, VaultV2BlueMarketPublicAllocatorConfigUtils, VaultV2BluePublicAllocatorConfigUtils,
|
|
6
|
+
getDefaultPreLiquidationParams, MarketUtils, MathLib, SharesMath, VaultUtils, VaultV2BlueMarketPublicAllocatorConfigUtils, VaultV2BluePublicAllocatorConfigUtils, VaultV2Utils, } from "@morpho-org/blue-sdk";
|
|
7
7
|
export { catchRevertOnly, decodeBytes32String, getAuthorizationTypedData, getPermit2PermitTypedData, getPermit2TransferFromTypedData, getPermitTypedData, isContractRevertError, isTransportError, isUndecodableResultError, MetaMorphoAction, optionalBoolean, readContractRestructured, restructure, safeGetAddress, safeParseNumber, safeParseUnits, } from "@morpho-org/blue-sdk-viem";
|
package/lib/esm/blue/utils.js
CHANGED
|
@@ -2,5 +2,5 @@ export { AdaptiveCurveIrmLib, CapacityLimitReason,
|
|
|
2
2
|
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
|
3
3
|
defaultPreLiquidationParamsRegistry,
|
|
4
4
|
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
|
5
|
-
getDefaultPreLiquidationParams, MarketUtils, MathLib, SharesMath, VaultUtils, VaultV2BlueMarketPublicAllocatorConfigUtils, VaultV2BluePublicAllocatorConfigUtils,
|
|
5
|
+
getDefaultPreLiquidationParams, MarketUtils, MathLib, SharesMath, VaultUtils, VaultV2BlueMarketPublicAllocatorConfigUtils, VaultV2BluePublicAllocatorConfigUtils, VaultV2Utils, } from "@morpho-org/blue-sdk";
|
|
6
6
|
export { catchRevertOnly, decodeBytes32String, getAuthorizationTypedData, getPermit2PermitTypedData, getPermit2TransferFromTypedData, getPermitTypedData, isContractRevertError, isTransportError, isUndecodableResultError, MetaMorphoAction, optionalBoolean, readContractRestructured, restructure, safeGetAddress, safeParseNumber, safeParseUnits, } from "@morpho-org/blue-sdk-viem";
|
|
@@ -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.
|
|
@@ -151,7 +154,8 @@ export interface BlueActions {
|
|
|
151
154
|
*
|
|
152
155
|
* @param params.userAddress - User funding and receiving the supply position.
|
|
153
156
|
* @param params.marketData - Snapshot of this market from `getMarketData()` (or `fetchMarket` in
|
|
154
|
-
* `@morpho-org/blue-sdk-viem`),
|
|
157
|
+
* `@morpho-org/blue-sdk-viem`), checked only for `MarketIdMismatchError`. To check the dead-deposit
|
|
158
|
+
* rule, call `validateBlueMarketDeadShares` on the snapshot yourself before building.
|
|
155
159
|
* @param params.assets - Gross loan-token assets funded before the referral fee.
|
|
156
160
|
* @param params.nativeAmount - Optional full native funding; must equal `assets` and requires wNative.
|
|
157
161
|
* @param params.deadline - Final call deadline in Unix seconds.
|
|
@@ -180,8 +184,6 @@ export interface BlueActions {
|
|
|
180
184
|
* @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
|
|
181
185
|
* @throws {UnknownAddressError} when BlueBundlesV1 is not registered.
|
|
182
186
|
* @throws {MarketIdMismatchError} when `marketData` belongs to another market.
|
|
183
|
-
* @throws {MissingDeadSharesDataError} when `marketData` has no `deadSupplyShares`.
|
|
184
|
-
* @throws {InsufficientDeadSharesError} when the market holds fewer than `MIN_DEAD_SHARES` supply shares at `DEAD_ADDRESS`.
|
|
185
187
|
* @throws {UnknownTokenError} from `getRequirements()` when the funded token's `decimals()` is unusable.
|
|
186
188
|
* @throws {MalformedTokenMetadataError} when the token's `eip712Domain()` or
|
|
187
189
|
* `bytes32` `name`/`symbol` retry returns non-empty data that does not decode, or when the
|
|
@@ -223,8 +225,7 @@ export interface BlueActions {
|
|
|
223
225
|
readonly referralFeeRecipient?: Address;
|
|
224
226
|
}): ActionOutput<BlueSupplyAction, readonly RequirementSignature[], BlueTokenRequirementsParams>;
|
|
225
227
|
/**
|
|
226
|
-
* @deprecated Pass `marketData` from `getMarketData()
|
|
227
|
-
* Snapshot-free supply is unprotected and will be removed in the next major after one minor.
|
|
228
|
+
* @deprecated Pass `marketData` from `getMarketData()`; the snapshot-free overload is removed in the next major.
|
|
228
229
|
*/
|
|
229
230
|
(params: {
|
|
230
231
|
readonly userAddress: Address;
|
|
@@ -316,6 +317,76 @@ export interface BlueActions {
|
|
|
316
317
|
readonly referralFeePct?: bigint;
|
|
317
318
|
readonly referralFeeRecipient?: Address;
|
|
318
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>;
|
|
319
390
|
/**
|
|
320
391
|
* Prepares a direct BlueBundlesV1 loan-asset borrow.
|
|
321
392
|
*
|
|
@@ -1002,8 +1073,7 @@ export declare class MorphoBlue implements BlueActions {
|
|
|
1002
1073
|
readonly referralFeeRecipient?: Address;
|
|
1003
1074
|
}): ActionOutput<BlueSupplyAction, readonly RequirementSignature[], BlueTokenRequirementsParams>;
|
|
1004
1075
|
/**
|
|
1005
|
-
* @deprecated Pass `marketData` from `getMarketData()
|
|
1006
|
-
* Snapshot-free supply is unprotected and will be removed in the next major after one minor.
|
|
1076
|
+
* @deprecated Pass `marketData` from `getMarketData()`; the snapshot-free overload is removed in the next major.
|
|
1007
1077
|
*/
|
|
1008
1078
|
supply(params: {
|
|
1009
1079
|
readonly userAddress: Address;
|
|
@@ -1025,6 +1095,12 @@ export declare class MorphoBlue implements BlueActions {
|
|
|
1025
1095
|
getRequirements: () => Promise<readonly ActionRequirement[]>;
|
|
1026
1096
|
buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<import("../../types/action.js").Transaction<BlueWithdrawAction>>;
|
|
1027
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>;
|
|
1028
1104
|
/** {@inheritDoc BlueActions.supplyCollateral} */
|
|
1029
1105
|
supplyCollateral(params: {
|
|
1030
1106
|
readonly userAddress: Address;
|
|
@@ -3,13 +3,13 @@ import { fetchAccrualPosition, fetchAccrualVaultV2, fetchMarket, fetchVaultV2Blu
|
|
|
3
3
|
import { getChainAddress, getChainAddresses, Time, } from "@morpho-org/morpho-ts";
|
|
4
4
|
import { erc20Abi, isAddressEqual, maxUint256 } from "viem";
|
|
5
5
|
import { readContract } from "viem/actions";
|
|
6
|
+
import { blueAbi, midnightBlueBuyCallbackAbi, midnightBlueBuyCallbackFactoryAbi, } from "../../abis.js";
|
|
6
7
|
import { getBlueBundlesV1PenaltyAssets, getBlueBundlesV1PublicAllocations, getBlueBundlesV1ReferralFeeAssets, normalizeBlueBundlesV1CommonParams, selectBlueBundlesV1RequirementSignatures, validateBlueBundlesV1NativeFunding, } from "../../actions/blue/common.js";
|
|
7
|
-
import { blueBorrow, blueRefinance, blueRepay, blueRepayWithdrawCollateral, blueSupply, blueSupplyCollateral, blueSupplyCollateralBorrow, blueWithdraw, blueWithdrawCollateral, getBlueAuthorizationRequirement, } from "../../actions/index.js";
|
|
8
|
+
import { blueBorrow, blueRefinance, blueRepay, blueRepayWithdrawCollateral, blueSupply, blueSupplyCollateral, blueSupplyCollateralBorrow, blueWithdraw, blueWithdrawBuyCallback, blueWithdrawCollateral, getBlueAuthorizationRequirement, } from "../../actions/index.js";
|
|
8
9
|
import { validateClientChainId } from "../../actions/requirements/validateClientChainId.js";
|
|
9
|
-
import { validateBlueMarketDeadShares } from "../../helpers/deadShares.js";
|
|
10
10
|
import { DEFAULT_LLTV_BUFFER, validateAccrualPosition, validateChainId, validatePositionHealth, validatePositionHealthAfterWithdraw, validateRepayAmount, validateRepayShares, validateWithdrawAmount, validateWithdrawShares, } from "../../helpers/index.js";
|
|
11
11
|
import { validateMarketParamsId } from "../../helpers/validate.js";
|
|
12
|
-
import { ExpiredDeadlineError, InputExceedsMaxError, MarketIdMismatchError, MaxRepayAssetsBelowRepayAssetsError, MissingAccrualPositionError, MutuallyExclusiveRepayAmountsError, MutuallyExclusiveWithdrawAmountsError, NegativeInputError, NonPositiveInputError, ReallocationsRequireBorrowError, RefinanceSameMarketError, RefinanceTokenMismatchError, } from "../../types/index.js";
|
|
12
|
+
import { BlueBuyCallbackOwnerMismatchError, BlueBuyCallbackUnauthorizedError, EmptyBlueSupplyPositionError, ExpiredDeadlineError, InputExceedsMaxError, InsufficientBlueLiquidityError, MarketIdMismatchError, MaxRepayAssetsBelowRepayAssetsError, MissingAccrualPositionError, MutuallyExclusiveRepayAmountsError, MutuallyExclusiveWithdrawAmountsError, NegativeInputError, NonPositiveInputError, NotBlueBuyCallbackError, ReallocationsRequireBorrowError, RefinanceSameMarketError, RefinanceTokenMismatchError, } from "../../types/index.js";
|
|
13
13
|
import { assertRegistryTargetsHaveCode } from "../requirements/assertContractCode.js";
|
|
14
14
|
import { getBundlesTokenRequirements } from "../requirements/index.js";
|
|
15
15
|
import { VaultV2BlueReallocationData } from "../vaultV2BlueReallocationData.js";
|
|
@@ -141,8 +141,6 @@ export class MorphoBlue {
|
|
|
141
141
|
if (params.marketData.id !== this.marketParams.id) {
|
|
142
142
|
throw new MarketIdMismatchError(params.marketData.id, this.marketParams.id);
|
|
143
143
|
}
|
|
144
|
-
// Throws when the market lacks a sufficient dead deposit; nothing to return.
|
|
145
|
-
validateBlueMarketDeadShares(params.marketData);
|
|
146
144
|
}
|
|
147
145
|
return {
|
|
148
146
|
getRequirements: (requirementsParams) => {
|
|
@@ -266,6 +264,90 @@ export class MorphoBlue {
|
|
|
266
264
|
},
|
|
267
265
|
};
|
|
268
266
|
}
|
|
267
|
+
/** {@inheritDoc BlueActions.withdrawBuyCallback} */
|
|
268
|
+
withdrawBuyCallback(params) {
|
|
269
|
+
const { userAddress, callbackAddress, positionData } = params;
|
|
270
|
+
validateChainId(this.client.viemClient.chain?.id, this.chainId);
|
|
271
|
+
if (positionData == null) {
|
|
272
|
+
throw new MissingAccrualPositionError(this.marketParams.id);
|
|
273
|
+
}
|
|
274
|
+
validateAccrualPosition({
|
|
275
|
+
positionData,
|
|
276
|
+
expectedMarketId: this.marketParams.id,
|
|
277
|
+
expectedUser: callbackAddress,
|
|
278
|
+
});
|
|
279
|
+
const shares = positionData.supplyShares;
|
|
280
|
+
if (shares === 0n) {
|
|
281
|
+
throw new EmptyBlueSupplyPositionError({
|
|
282
|
+
market: this.marketParams.id,
|
|
283
|
+
user: callbackAddress,
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
const assets = positionData.supplyAssets;
|
|
287
|
+
const liquidity = positionData.market.liquidity;
|
|
288
|
+
if (assets > liquidity) {
|
|
289
|
+
throw new InsufficientBlueLiquidityError({
|
|
290
|
+
market: this.marketParams.id,
|
|
291
|
+
assets,
|
|
292
|
+
liquidity,
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
const blue = getChainAddress(this.chainId, "blue");
|
|
296
|
+
const factory = getChainAddress(this.chainId, "midnightBlueBuyCallbackFactory");
|
|
297
|
+
const tx = blueWithdrawBuyCallback({
|
|
298
|
+
market: { chainId: this.chainId, marketParams: this.marketParams },
|
|
299
|
+
args: { callbackAddress, userAddress, shares },
|
|
300
|
+
metadata: this.client.options.metadata,
|
|
301
|
+
});
|
|
302
|
+
return {
|
|
303
|
+
getRequirements: async () => {
|
|
304
|
+
const viemClient = this.client.viemClient;
|
|
305
|
+
await validateClientChainId(viemClient, this.chainId);
|
|
306
|
+
await assertRegistryTargetsHaveCode(viemClient, this.chainId, [
|
|
307
|
+
{ role: "blue", address: blue },
|
|
308
|
+
{ role: "midnightBlueBuyCallbackFactory", address: factory },
|
|
309
|
+
]);
|
|
310
|
+
// Check the factory first: OWNER() on an arbitrary address can revert or lie.
|
|
311
|
+
const isBlueBuyCallback = await readContract(viemClient, {
|
|
312
|
+
address: factory,
|
|
313
|
+
abi: midnightBlueBuyCallbackFactoryAbi,
|
|
314
|
+
functionName: "isBlueBuyCallback",
|
|
315
|
+
args: [callbackAddress],
|
|
316
|
+
});
|
|
317
|
+
if (!isBlueBuyCallback) {
|
|
318
|
+
throw new NotBlueBuyCallbackError(callbackAddress);
|
|
319
|
+
}
|
|
320
|
+
const [owner, isAuthorized] = await Promise.all([
|
|
321
|
+
readContract(viemClient, {
|
|
322
|
+
address: callbackAddress,
|
|
323
|
+
abi: midnightBlueBuyCallbackAbi,
|
|
324
|
+
functionName: "OWNER",
|
|
325
|
+
}),
|
|
326
|
+
readContract(viemClient, {
|
|
327
|
+
address: blue,
|
|
328
|
+
abi: blueAbi,
|
|
329
|
+
functionName: "isAuthorized",
|
|
330
|
+
args: [callbackAddress, userAddress],
|
|
331
|
+
}),
|
|
332
|
+
]);
|
|
333
|
+
if (!isAddressEqual(owner, userAddress)) {
|
|
334
|
+
throw new BlueBuyCallbackOwnerMismatchError({
|
|
335
|
+
callback: callbackAddress,
|
|
336
|
+
owner,
|
|
337
|
+
userAddress,
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
if (!isAuthorized) {
|
|
341
|
+
throw new BlueBuyCallbackUnauthorizedError({
|
|
342
|
+
callback: callbackAddress,
|
|
343
|
+
userAddress,
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
return [];
|
|
347
|
+
},
|
|
348
|
+
buildTx: () => tx,
|
|
349
|
+
};
|
|
350
|
+
}
|
|
269
351
|
/** {@inheritDoc BlueActions.supplyCollateral} */
|
|
270
352
|
supplyCollateral(params) {
|
|
271
353
|
const { userAddress, collateralAssets, nativeAmount, deadline, referralFeePct, referralFeeRecipient, } = params;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
export type { IAccrualPosition as IBlueAccrualPosition, IAccrualVault, IAccrualVaultV2, IAccrualVaultV2Adapter,
|
|
1
|
+
export type { IAccrualPosition as IBlueAccrualPosition, IAccrualVault, IAccrualVaultV2, IAccrualVaultV2Adapter, IAccrualVaultV2MorphoMarketV1Adapter, IAccrualVaultV2MorphoMarketV1AdapterV2, IAccrualVaultV2MorphoVaultV1Adapter, IAssetBalances, IEip5267Domain, IHolding, IMarket as IBlueMarket, IMarketParams as IBlueMarketParams, IPosition as IBluePosition,
|
|
2
2
|
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
|
3
3
|
IPreLiquidationParams as IBluePreLiquidationParams,
|
|
4
4
|
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
|
5
|
-
IPreLiquidationPosition as IBluePreLiquidationPosition, IToken, IVault, IVaultConfig, IVaultMarketAllocation, IVaultMarketConfig, IVaultToken, IVaultUser, IVaultV2, IVaultV2Adapter, IVaultV2Allocation, IVaultV2BlueMarketPublicAllocatorConfig, IVaultV2BluePublicAllocatorConfig,
|
|
6
|
-
export { AccrualPosition as BlueAccrualPosition, AccrualVault, AccrualVaultV2,
|
|
5
|
+
IPreLiquidationPosition as IBluePreLiquidationPosition, IToken, IVault, IVaultConfig, IVaultMarketAllocation, IVaultMarketConfig, IVaultToken, IVaultUser, IVaultV2, IVaultV2Adapter, IVaultV2Allocation, IVaultV2BlueMarketPublicAllocatorConfig, IVaultV2BluePublicAllocatorConfig, IVaultV2MorphoMarketV1Adapter, IVaultV2MorphoMarketV1AdapterV2, IVaultV2MorphoVaultV1Adapter, PeripheralBalance, PeripheralBalanceType, } from "@morpho-org/blue-sdk";
|
|
6
|
+
export { AccrualPosition as BlueAccrualPosition, AccrualVault, AccrualVaultV2, AccrualVaultV2MorphoMarketV1Adapter, AccrualVaultV2MorphoMarketV1AdapterV2, AccrualVaultV2MorphoVaultV1Adapter, AssetBalances, ConstantWrappedToken, Eip5267Domain, ExchangeRateWrappedToken, Holding, Market as BlueMarket, MarketParams as BlueMarketParams, Position as BluePosition,
|
|
7
7
|
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
|
8
8
|
PreLiquidationParams as BluePreLiquidationParams,
|
|
9
9
|
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
|
10
|
-
PreLiquidationPosition as BluePreLiquidationPosition, Token, User as BlueUser, Vault, VaultConfig, VaultMarketAllocation, VaultMarketConfig, VaultToken, VaultUser, VaultV2, VaultV2Adapter, VaultV2BlueMarketPublicAllocatorConfig, VaultV2BluePublicAllocatorConfig,
|
|
10
|
+
PreLiquidationPosition as BluePreLiquidationPosition, Token, User as BlueUser, Vault, VaultConfig, VaultMarketAllocation, VaultMarketConfig, VaultToken, VaultUser, VaultV2, VaultV2Adapter, VaultV2BlueMarketPublicAllocatorConfig, VaultV2BluePublicAllocatorConfig, VaultV2MorphoMarketV1Adapter, VaultV2MorphoMarketV1AdapterV2, VaultV2MorphoVaultV1Adapter, WrappedToken, } from "@morpho-org/blue-sdk";
|
|
11
11
|
export type { AnyTree as MidnightAnyTree, AnyTreeSnapshot as MidnightAnyTreeSnapshot, BuildOfferParams as MidnightBuildOfferParams, CollateralParams as MidnightCollateralParams, EcrecoverTreeCreateRequest as MidnightEcrecoverTreeCreateRequest, GroupInput as MidnightGroupInput, IAccrualPosition as IMidnightAccrualPosition, ICollateralParams as IMidnightCollateralParams, IGroup as IMidnightGroup, IMarket as IMidnightMarket, IMarketParams as IMidnightMarketParams, IOffer as IMidnightOffer, IPosition as IMidnightPosition, MarketInput as MidnightMarketInput, OfferStruct as MidnightOfferStruct, PriceRatifierV1TreeCreateRequest as MidnightPriceRatifierV1TreeCreateRequest, RateRatifierV1TreeCreateRequest as MidnightRateRatifierV1TreeCreateRequest, RatifierKind as MidnightRatifierKind, RatifierTreeInput as MidnightRatifierTreeInput, RatifierTypes as MidnightRatifierTypes, SetterTreeCreateRequest as MidnightSetterTreeCreateRequest, SettlementFeeCbps as MidnightSettlementFeeCbps, TreeCreateParams as MidnightTreeCreateParams, TreeCreateRequest as MidnightTreeCreateRequest, TreeData as MidnightTreeData, TreeDescriptor as MidnightTreeDescriptor, TreeEntry as MidnightTreeEntry, TreeInput as MidnightTreeInput, TreeLike as MidnightTreeLike, TreeMempoolValidateParams as MidnightTreeMempoolValidateParams, TreeMempoolValidateRatification as MidnightTreeMempoolValidateRatification, TreeProof as MidnightTreeProof, TreeSnapshot as MidnightTreeSnapshot, TypedRatifierTreeInput as MidnightTypedRatifierTreeInput, TypedTreeMempoolValidateParams as MidnightTypedTreeMempoolValidateParams, } from "@morpho-org/midnight-sdk";
|
|
12
12
|
export { AccrualPosition as MidnightAccrualPosition, Group as MidnightGroup, Market as MidnightMarket, MarketParams as MidnightMarketParams, Offer as MidnightOffer, Position as MidnightPosition, Tree as MidnightTree, } from "@morpho-org/midnight-sdk";
|
|
13
13
|
export type { BlueActions, BlueTokenRequirementsParams, } from "./blue/index.js";
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export { AccrualPosition as BlueAccrualPosition, AccrualVault, AccrualVaultV2,
|
|
1
|
+
export { AccrualPosition as BlueAccrualPosition, AccrualVault, AccrualVaultV2, AccrualVaultV2MorphoMarketV1Adapter, AccrualVaultV2MorphoMarketV1AdapterV2, AccrualVaultV2MorphoVaultV1Adapter, AssetBalances, ConstantWrappedToken, Eip5267Domain, ExchangeRateWrappedToken, Holding, Market as BlueMarket, MarketParams as BlueMarketParams, Position as BluePosition,
|
|
2
2
|
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
|
3
3
|
PreLiquidationParams as BluePreLiquidationParams,
|
|
4
4
|
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
|
5
|
-
PreLiquidationPosition as BluePreLiquidationPosition, Token, User as BlueUser, Vault, VaultConfig, VaultMarketAllocation, VaultMarketConfig, VaultToken, VaultUser, VaultV2, VaultV2Adapter, VaultV2BlueMarketPublicAllocatorConfig, VaultV2BluePublicAllocatorConfig,
|
|
5
|
+
PreLiquidationPosition as BluePreLiquidationPosition, Token, User as BlueUser, Vault, VaultConfig, VaultMarketAllocation, VaultMarketConfig, VaultToken, VaultUser, VaultV2, VaultV2Adapter, VaultV2BlueMarketPublicAllocatorConfig, VaultV2BluePublicAllocatorConfig, VaultV2MorphoMarketV1Adapter, VaultV2MorphoMarketV1AdapterV2, VaultV2MorphoVaultV1Adapter, WrappedToken, } from "@morpho-org/blue-sdk";
|
|
6
6
|
export { AccrualPosition as MidnightAccrualPosition, Group as MidnightGroup, Market as MidnightMarket, MarketParams as MidnightMarketParams, Offer as MidnightOffer, Position as MidnightPosition, Tree as MidnightTree, } from "@morpho-org/midnight-sdk";
|
|
7
7
|
export { MorphoBlue } from "./blue/index.js";
|
|
8
8
|
export { MorphoMidnight, } from "./midnight/index.js";
|
|
@@ -894,8 +894,7 @@ export declare class MorphoMidnight {
|
|
|
894
894
|
* @throws {MidnightMarketLiquidationCursorNotEnabledError} when an uncreated market uses a disabled liquidation cursor.
|
|
895
895
|
* @throws {MidnightMarketOracleWithoutCodeError} when an uncreated market's oracle has no code.
|
|
896
896
|
* @throws {viem.BaseError} when a pinned block, contract, or oracle-code read fails.
|
|
897
|
-
* @throws {
|
|
898
|
-
* @throws {InsufficientDeadSharesError} when `blueMarket` holds fewer than `MIN_DEAD_SHARES` supply shares at `DEAD_ADDRESS`.
|
|
897
|
+
* @throws {EmptyBlueParkingMarketError} when `blueMarket` has no supply shares.
|
|
899
898
|
* @throws {ZeroBlueParkingSharesError} when `assetsToPark` would mint no supply shares at the current share price (checked at preparation time only).
|
|
900
899
|
* @throws {MidnightReplacementGroupCancelledError} when a published group is also cancelled.
|
|
901
900
|
* @throws {InvalidMidnightHexInputError} when a cancellation group or `callbackSalt` is not 32-byte hex.
|
|
@@ -8,7 +8,6 @@ import { getMidnightApprovalRequirements, getMidnightAuthorizationRequirement, }
|
|
|
8
8
|
import { validateClientChainId } from "../../actions/requirements/validateClientChainId.js";
|
|
9
9
|
import { getMidnightBlueBuyCallbackAddress, getMidnightBlueBuyCallbackData, } from "../../helpers/callback.js";
|
|
10
10
|
import { MIDNIGHT_TAKE_MAX_DEADLINE_SECONDS } from "../../helpers/constant.js";
|
|
11
|
-
import { validateBlueMarketDeadShares } from "../../helpers/deadShares.js";
|
|
12
11
|
import { encodeMidnightMarketId, wrapMidnightEncoding, } from "../../helpers/encodeMidnightCalldata.js";
|
|
13
12
|
import { getMidnightMaxSafeDebt, validateChainId, } from "../../helpers/index.js";
|
|
14
13
|
import { validateMidnightAccount, validateMidnightAddress, } from "../../helpers/validateMidnightAccount.js";
|
|
@@ -17,7 +16,7 @@ import { validateMidnightMarket } from "../../helpers/validateMidnightMarket.js"
|
|
|
17
16
|
import { validateMidnightBytes32 } from "../../helpers/validateMidnightPublication.js";
|
|
18
17
|
import { validateMidnightTakeFeasibility } from "../../helpers/validateMidnightTakeFeasibility.js";
|
|
19
18
|
import { validateOfferSides } from "../../helpers/validateOfferSides.js";
|
|
20
|
-
import { AccrualPositionUserMismatchError, BorrowExceedsSafeLtvError, InsufficientMidnightWithdrawableLiquidityError, MarketIdMismatchError, MidnightInvalidAccountAddressError, MidnightOfferCallbackDataMismatchError, MidnightOfferCallbackMismatchError, MidnightOfferContinuousFeeCapError, MidnightOfferMakerMismatchError, MidnightOfferMarketAddressMismatchError, MidnightOfferMarketChainMismatchError, MidnightOfferMarketLoanTokenMismatchError, MidnightOfferNotReduceOnlyError, MidnightOfferRatifierMismatchError, MidnightOfferReduceOnlyError, MidnightOfferSellerReceiverMismatchError, MidnightRedeemExceedsCreditError, MidnightRepayExceedsDebtError, MidnightTakeDeadlineTooFarError, MidnightTakeTargetUnreachableError, MidnightZeroOnBehalfError, MissingAccrualPositionError, NegativeInputError, NoMidnightCreditToRedeemError, NonPositiveInputError, WithdrawExceedsCollateralError, WithdrawMakesPositionUnhealthyError, ZeroBlueParkingSharesError, } from "../../types/index.js";
|
|
19
|
+
import { AccrualPositionUserMismatchError, BorrowExceedsSafeLtvError, EmptyBlueParkingMarketError, InsufficientMidnightWithdrawableLiquidityError, MarketIdMismatchError, MidnightInvalidAccountAddressError, MidnightOfferCallbackDataMismatchError, MidnightOfferCallbackMismatchError, MidnightOfferContinuousFeeCapError, MidnightOfferMakerMismatchError, MidnightOfferMarketAddressMismatchError, MidnightOfferMarketChainMismatchError, MidnightOfferMarketLoanTokenMismatchError, MidnightOfferNotReduceOnlyError, MidnightOfferRatifierMismatchError, MidnightOfferReduceOnlyError, MidnightOfferSellerReceiverMismatchError, MidnightRedeemExceedsCreditError, MidnightRepayExceedsDebtError, MidnightTakeDeadlineTooFarError, MidnightTakeTargetUnreachableError, MidnightZeroOnBehalfError, MissingAccrualPositionError, NegativeInputError, NoMidnightCreditToRedeemError, NonPositiveInputError, WithdrawExceedsCollateralError, WithdrawMakesPositionUnhealthyError, ZeroBlueParkingSharesError, } from "../../types/index.js";
|
|
21
20
|
import { validateMidnightDeadline } from "./deadline.js";
|
|
22
21
|
import { fetchMidnightMakerOfferStates, offerMarketParams, validateMidnightMakerOfferCallbacks, validateMidnightMakerOfferStates, } from "./publication.js";
|
|
23
22
|
const validatePositionBinding = (params) => {
|
|
@@ -1527,8 +1526,7 @@ export class MorphoMidnight {
|
|
|
1527
1526
|
* @throws {MidnightMarketLiquidationCursorNotEnabledError} when an uncreated market uses a disabled liquidation cursor.
|
|
1528
1527
|
* @throws {MidnightMarketOracleWithoutCodeError} when an uncreated market's oracle has no code.
|
|
1529
1528
|
* @throws {viem.BaseError} when a pinned block, contract, or oracle-code read fails.
|
|
1530
|
-
* @throws {
|
|
1531
|
-
* @throws {InsufficientDeadSharesError} when `blueMarket` holds fewer than `MIN_DEAD_SHARES` supply shares at `DEAD_ADDRESS`.
|
|
1529
|
+
* @throws {EmptyBlueParkingMarketError} when `blueMarket` has no supply shares.
|
|
1532
1530
|
* @throws {ZeroBlueParkingSharesError} when `assetsToPark` would mint no supply shares at the current share price (checked at preparation time only).
|
|
1533
1531
|
* @throws {MidnightReplacementGroupCancelledError} when a published group is also cancelled.
|
|
1534
1532
|
* @throws {InvalidMidnightHexInputError} when a cancellation group or `callbackSalt` is not 32-byte hex.
|
|
@@ -1584,8 +1582,9 @@ export class MorphoMidnight {
|
|
|
1584
1582
|
}),
|
|
1585
1583
|
]);
|
|
1586
1584
|
const market = _try(() => fetched.accrueInterest(MathLib.max(Time.timestamp(), fetched.lastUpdate)), UnsupportedMarketIrmError) ?? fetched;
|
|
1587
|
-
|
|
1588
|
-
|
|
1585
|
+
if (market.totalSupplyShares === 0n) {
|
|
1586
|
+
throw new EmptyBlueParkingMarketError({ marketId: blueMarketId });
|
|
1587
|
+
}
|
|
1589
1588
|
if (market.toSupplyShares(params.assetsToPark, "Down") === 0n) {
|
|
1590
1589
|
throw new ZeroBlueParkingSharesError({
|
|
1591
1590
|
marketId: blueMarketId,
|
|
@@ -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.
|