@morpho-org/morpho-sdk 1.0.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/LICENSE +21 -0
- package/README.md +496 -0
- package/lib/actions/index.d.ts +4 -0
- package/lib/actions/index.js +20 -0
- package/lib/actions/marketV1/borrow.d.ts +34 -0
- package/lib/actions/marketV1/borrow.js +62 -0
- package/lib/actions/marketV1/buildReallocationActions.d.ts +17 -0
- package/lib/actions/marketV1/buildReallocationActions.js +36 -0
- package/lib/actions/marketV1/index.d.ts +6 -0
- package/lib/actions/marketV1/index.js +22 -0
- package/lib/actions/marketV1/repay.d.ts +44 -0
- package/lib/actions/marketV1/repay.js +93 -0
- package/lib/actions/marketV1/repayWithdrawCollateral.d.ts +51 -0
- package/lib/actions/marketV1/repayWithdrawCollateral.js +108 -0
- package/lib/actions/marketV1/supplyCollateral.d.ts +28 -0
- package/lib/actions/marketV1/supplyCollateral.js +85 -0
- package/lib/actions/marketV1/supplyCollateralBorrow.d.ts +37 -0
- package/lib/actions/marketV1/supplyCollateralBorrow.js +109 -0
- package/lib/actions/marketV1/withdrawCollateral.d.ts +28 -0
- package/lib/actions/marketV1/withdrawCollateral.js +51 -0
- package/lib/actions/requirements/encode/encodeErc20Approval.d.ts +10 -0
- package/lib/actions/requirements/encode/encodeErc20Approval.js +25 -0
- package/lib/actions/requirements/encode/encodeErc20Permit.d.ts +13 -0
- package/lib/actions/requirements/encode/encodeErc20Permit.js +70 -0
- package/lib/actions/requirements/encode/encodeErc20Permit2.d.ts +11 -0
- package/lib/actions/requirements/encode/encodeErc20Permit2.js +70 -0
- package/lib/actions/requirements/encode/index.d.ts +3 -0
- package/lib/actions/requirements/encode/index.js +19 -0
- package/lib/actions/requirements/getMorphoAuthorizationRequirement.d.ts +21 -0
- package/lib/actions/requirements/getMorphoAuthorizationRequirement.js +55 -0
- package/lib/actions/requirements/getRequirements.d.ts +42 -0
- package/lib/actions/requirements/getRequirements.js +80 -0
- package/lib/actions/requirements/getRequirementsAction.d.ts +17 -0
- package/lib/actions/requirements/getRequirementsAction.js +64 -0
- package/lib/actions/requirements/getRequirementsApproval.d.ts +31 -0
- package/lib/actions/requirements/getRequirementsApproval.js +51 -0
- package/lib/actions/requirements/getRequirementsPermit.d.ts +28 -0
- package/lib/actions/requirements/getRequirementsPermit.js +40 -0
- package/lib/actions/requirements/getRequirementsPermit2.d.ts +37 -0
- package/lib/actions/requirements/getRequirementsPermit2.js +59 -0
- package/lib/actions/requirements/index.d.ts +6 -0
- package/lib/actions/requirements/index.js +22 -0
- package/lib/actions/vaultV1/deposit.d.ts +41 -0
- package/lib/actions/vaultV1/deposit.js +116 -0
- package/lib/actions/vaultV1/index.d.ts +4 -0
- package/lib/actions/vaultV1/index.js +20 -0
- package/lib/actions/vaultV1/migrateToV2.d.ts +50 -0
- package/lib/actions/vaultV1/migrateToV2.js +108 -0
- package/lib/actions/vaultV1/redeem.d.ts +29 -0
- package/lib/actions/vaultV1/redeem.js +48 -0
- package/lib/actions/vaultV1/withdraw.d.ts +29 -0
- package/lib/actions/vaultV1/withdraw.js +48 -0
- package/lib/actions/vaultV2/deposit.d.ts +41 -0
- package/lib/actions/vaultV2/deposit.js +116 -0
- package/lib/actions/vaultV2/forceRedeem.d.ts +48 -0
- package/lib/actions/vaultV2/forceRedeem.js +85 -0
- package/lib/actions/vaultV2/forceWithdraw.d.ts +40 -0
- package/lib/actions/vaultV2/forceWithdraw.js +85 -0
- package/lib/actions/vaultV2/index.d.ts +5 -0
- package/lib/actions/vaultV2/index.js +21 -0
- package/lib/actions/vaultV2/redeem.d.ts +32 -0
- package/lib/actions/vaultV2/redeem.js +51 -0
- package/lib/actions/vaultV2/withdraw.d.ts +32 -0
- package/lib/actions/vaultV2/withdraw.js +51 -0
- package/lib/client/index.d.ts +2 -0
- package/lib/client/index.js +18 -0
- package/lib/client/morphoClient.d.ts +25 -0
- package/lib/client/morphoClient.js +28 -0
- package/lib/client/morphoViemExtension.d.ts +39 -0
- package/lib/client/morphoViemExtension.js +40 -0
- package/lib/entities/index.d.ts +3 -0
- package/lib/entities/index.js +19 -0
- package/lib/entities/marketV1/index.d.ts +1 -0
- package/lib/entities/marketV1/index.js +17 -0
- package/lib/entities/marketV1/marketV1.d.ts +290 -0
- package/lib/entities/marketV1/marketV1.js +531 -0
- package/lib/entities/vaultV1/index.d.ts +1 -0
- package/lib/entities/vaultV1/index.js +17 -0
- package/lib/entities/vaultV1/vaultV1.d.ts +133 -0
- package/lib/entities/vaultV1/vaultV1.js +186 -0
- package/lib/entities/vaultV2/index.d.ts +1 -0
- package/lib/entities/vaultV2/index.js +17 -0
- package/lib/entities/vaultV2/vaultV2.d.ts +180 -0
- package/lib/entities/vaultV2/vaultV2.js +167 -0
- package/lib/helpers/computeReallocations.d.ts +23 -0
- package/lib/helpers/computeReallocations.js +98 -0
- package/lib/helpers/constant.d.ts +6 -0
- package/lib/helpers/constant.js +10 -0
- package/lib/helpers/encodeDeallocation.d.ts +10 -0
- package/lib/helpers/encodeDeallocation.js +37 -0
- package/lib/helpers/index.d.ts +4 -0
- package/lib/helpers/index.js +22 -0
- package/lib/helpers/metadata.d.ts +33 -0
- package/lib/helpers/metadata.js +49 -0
- package/lib/helpers/slippage.d.ts +46 -0
- package/lib/helpers/slippage.js +73 -0
- package/lib/helpers/validate.d.ts +156 -0
- package/lib/helpers/validate.js +287 -0
- package/lib/index.d.ts +5 -0
- package/lib/index.js +21 -0
- package/lib/types/action.d.ts +216 -0
- package/lib/types/action.js +26 -0
- package/lib/types/client.d.ts +15 -0
- package/lib/types/client.js +2 -0
- package/lib/types/data.d.ts +2 -0
- package/lib/types/data.js +2 -0
- package/lib/types/deallocation.d.ts +15 -0
- package/lib/types/deallocation.js +2 -0
- package/lib/types/entity.d.ts +5 -0
- package/lib/types/entity.js +2 -0
- package/lib/types/error.d.ts +166 -0
- package/lib/types/error.js +285 -0
- package/lib/types/index.d.ts +7 -0
- package/lib/types/index.js +23 -0
- package/lib/types/metadata.d.ts +4 -0
- package/lib/types/metadata.js +2 -0
- package/lib/types/sharedLiquidity.d.ts +41 -0
- package/lib/types/sharedLiquidity.js +2 -0
- package/package.json +81 -0
- package/src/index.ts +5 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./morphoClient"), exports);
|
|
18
|
+
__exportStar(require("./morphoViemExtension"), exports);
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { MarketParams } from "@morpho-org/blue-sdk";
|
|
2
|
+
import type { Address, Client } from "viem";
|
|
3
|
+
import { MorphoMarketV1, MorphoVaultV1, MorphoVaultV2 } from "../entities";
|
|
4
|
+
import type { Metadata, MorphoClientType } from "../types";
|
|
5
|
+
export declare class MorphoClient implements MorphoClientType {
|
|
6
|
+
readonly viemClient: Client;
|
|
7
|
+
readonly _options?: {
|
|
8
|
+
readonly supportSignature?: boolean;
|
|
9
|
+
readonly supportDeployless?: boolean;
|
|
10
|
+
readonly metadata?: Metadata;
|
|
11
|
+
} | undefined;
|
|
12
|
+
readonly options: {
|
|
13
|
+
readonly supportSignature: boolean;
|
|
14
|
+
readonly supportDeployless?: boolean;
|
|
15
|
+
readonly metadata?: Metadata;
|
|
16
|
+
};
|
|
17
|
+
constructor(viemClient: Client, _options?: {
|
|
18
|
+
readonly supportSignature?: boolean;
|
|
19
|
+
readonly supportDeployless?: boolean;
|
|
20
|
+
readonly metadata?: Metadata;
|
|
21
|
+
} | undefined);
|
|
22
|
+
vaultV1(vault: Address, chainId: number): MorphoVaultV1;
|
|
23
|
+
vaultV2(vault: Address, chainId: number): MorphoVaultV2;
|
|
24
|
+
marketV1(marketParams: MarketParams, chainId: number): MorphoMarketV1;
|
|
25
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MorphoClient = void 0;
|
|
4
|
+
const entities_1 = require("../entities");
|
|
5
|
+
class MorphoClient {
|
|
6
|
+
viemClient;
|
|
7
|
+
_options;
|
|
8
|
+
options;
|
|
9
|
+
constructor(viemClient, _options) {
|
|
10
|
+
this.viemClient = viemClient;
|
|
11
|
+
this._options = _options;
|
|
12
|
+
this.options = {
|
|
13
|
+
..._options,
|
|
14
|
+
supportSignature: _options?.supportSignature ?? false,
|
|
15
|
+
supportDeployless: _options?.supportDeployless,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
vaultV1(vault, chainId) {
|
|
19
|
+
return new entities_1.MorphoVaultV1(this, vault, chainId);
|
|
20
|
+
}
|
|
21
|
+
vaultV2(vault, chainId) {
|
|
22
|
+
return new entities_1.MorphoVaultV2(this, vault, chainId);
|
|
23
|
+
}
|
|
24
|
+
marketV1(marketParams, chainId) {
|
|
25
|
+
return new entities_1.MorphoMarketV1(this, marketParams, chainId);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.MorphoClient = MorphoClient;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { Client } from "viem";
|
|
2
|
+
import type { Metadata } from "../types";
|
|
3
|
+
import { MorphoClient } from "./morphoClient";
|
|
4
|
+
/**
|
|
5
|
+
* Morpho extension for viem clients.
|
|
6
|
+
* Adds `morpho` namespace with `vaultV1` and `vaultV2` accessors.
|
|
7
|
+
*
|
|
8
|
+
* @param metadata - (Optional) Metadata appended to all transactions for analytics.
|
|
9
|
+
* @param supportSignature - (Optional) Enable off-chain permit/permit2 approvals.
|
|
10
|
+
* @param supportDeployless - (Optional) Enable deployless reads for on-chain data fetching.
|
|
11
|
+
* @returns Extension function that adds morpho namespace to viem clients.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* import { createWalletClient, http } from 'viem';
|
|
16
|
+
* import { mainnet } from 'viem/chains';
|
|
17
|
+
* import { morphoViemExtension } from '@morpho-org/morpho-sdk';
|
|
18
|
+
*
|
|
19
|
+
* const client = createWalletClient({
|
|
20
|
+
* chain: mainnet,
|
|
21
|
+
* transport: http(),
|
|
22
|
+
* account: '0x...',
|
|
23
|
+
* }).extend(morphoViemExtension());
|
|
24
|
+
*
|
|
25
|
+
* // VaultV1 (MetaMorpho)
|
|
26
|
+
* const vaultV1 = client.morpho.vaultV1('0x...', 1);
|
|
27
|
+
* const depositV1 = await vaultV1.deposit({ amount: 1000000000000000000n, userAddress: '0x...' });
|
|
28
|
+
*
|
|
29
|
+
* // VaultV2
|
|
30
|
+
* const vaultV2 = client.morpho.vaultV2('0x...', 1);
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export declare function morphoViemExtension(_options?: {
|
|
34
|
+
readonly metadata?: Metadata;
|
|
35
|
+
readonly supportSignature?: boolean;
|
|
36
|
+
readonly supportDeployless?: boolean;
|
|
37
|
+
}): <TClient extends Client>(client: TClient) => {
|
|
38
|
+
morpho: MorphoClient;
|
|
39
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.morphoViemExtension = morphoViemExtension;
|
|
4
|
+
const morphoClient_1 = require("./morphoClient");
|
|
5
|
+
/**
|
|
6
|
+
* Morpho extension for viem clients.
|
|
7
|
+
* Adds `morpho` namespace with `vaultV1` and `vaultV2` accessors.
|
|
8
|
+
*
|
|
9
|
+
* @param metadata - (Optional) Metadata appended to all transactions for analytics.
|
|
10
|
+
* @param supportSignature - (Optional) Enable off-chain permit/permit2 approvals.
|
|
11
|
+
* @param supportDeployless - (Optional) Enable deployless reads for on-chain data fetching.
|
|
12
|
+
* @returns Extension function that adds morpho namespace to viem clients.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* import { createWalletClient, http } from 'viem';
|
|
17
|
+
* import { mainnet } from 'viem/chains';
|
|
18
|
+
* import { morphoViemExtension } from '@morpho-org/morpho-sdk';
|
|
19
|
+
*
|
|
20
|
+
* const client = createWalletClient({
|
|
21
|
+
* chain: mainnet,
|
|
22
|
+
* transport: http(),
|
|
23
|
+
* account: '0x...',
|
|
24
|
+
* }).extend(morphoViemExtension());
|
|
25
|
+
*
|
|
26
|
+
* // VaultV1 (MetaMorpho)
|
|
27
|
+
* const vaultV1 = client.morpho.vaultV1('0x...', 1);
|
|
28
|
+
* const depositV1 = await vaultV1.deposit({ amount: 1000000000000000000n, userAddress: '0x...' });
|
|
29
|
+
*
|
|
30
|
+
* // VaultV2
|
|
31
|
+
* const vaultV2 = client.morpho.vaultV2('0x...', 1);
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
function morphoViemExtension(_options) {
|
|
35
|
+
return (client) => {
|
|
36
|
+
return {
|
|
37
|
+
morpho: new morphoClient_1.MorphoClient(client, _options),
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./marketV1"), exports);
|
|
18
|
+
__exportStar(require("./vaultV1"), exports);
|
|
19
|
+
__exportStar(require("./vaultV2"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./marketV1";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./marketV1"), exports);
|
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
import { type AccrualPosition, type Market, type MarketParams } from "@morpho-org/blue-sdk";
|
|
2
|
+
import { type MinimalBlock, SimulationState } from "@morpho-org/simulation-sdk";
|
|
3
|
+
import type { Address } from "viem";
|
|
4
|
+
import { type DepositAmountArgs, type ERC20ApprovalAction, type MarketV1BorrowAction, type MarketV1RepayAction, type MarketV1RepayWithdrawCollateralAction, type MarketV1SupplyCollateralAction, type MarketV1SupplyCollateralBorrowAction, type MarketV1WithdrawCollateralAction, type MorphoAuthorizationAction, type MorphoClientType, type ReallocationComputeOptions, type RepayAmountArgs, type Requirement, type RequirementSignature, type Transaction, type VaultReallocation } from "../../types";
|
|
5
|
+
import type { FetchParameters } from "../../types/data";
|
|
6
|
+
export interface MarketV1Actions {
|
|
7
|
+
/**
|
|
8
|
+
* Fetches the latest market data with accrued interest.
|
|
9
|
+
*
|
|
10
|
+
* @param parameters - Optional fetch parameters (block number, state overrides).
|
|
11
|
+
* @returns Market state including total supply/borrow assets and shares.
|
|
12
|
+
*/
|
|
13
|
+
getMarketData: (parameters?: FetchParameters) => Promise<Market>;
|
|
14
|
+
/**
|
|
15
|
+
* Fetches the user's position in this market with accrued interest.
|
|
16
|
+
*
|
|
17
|
+
* @param userAddress - The user whose position to fetch.
|
|
18
|
+
* @param parameters - Optional fetch parameters (block number, state overrides).
|
|
19
|
+
* @returns Accrual position with health metrics (maxBorrowAssets, ltv, isHealthy).
|
|
20
|
+
*/
|
|
21
|
+
getPositionData: (userAddress: Address, parameters?: FetchParameters) => Promise<AccrualPosition>;
|
|
22
|
+
/**
|
|
23
|
+
* Prepares a supply-collateral transaction.
|
|
24
|
+
*
|
|
25
|
+
* Routed through bundler via GeneralAdapter1.
|
|
26
|
+
* `getRequirements` returns ERC20 approval or permit for GeneralAdapter1.
|
|
27
|
+
* When `nativeAmount` is provided, native token is wrapped; collateral must be wNative.
|
|
28
|
+
*
|
|
29
|
+
* @param params - Supply collateral parameters.
|
|
30
|
+
* @returns Object with `buildTx` and `getRequirements`.
|
|
31
|
+
*/
|
|
32
|
+
supplyCollateral: (params: {
|
|
33
|
+
userAddress: Address;
|
|
34
|
+
} & DepositAmountArgs) => {
|
|
35
|
+
buildTx: (requirementSignature?: RequirementSignature) => Readonly<Transaction<MarketV1SupplyCollateralAction>>;
|
|
36
|
+
getRequirements: (params?: {
|
|
37
|
+
useSimplePermit?: boolean;
|
|
38
|
+
}) => Promise<(Readonly<Transaction<ERC20ApprovalAction>> | Requirement)[]>;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Prepares a borrow transaction.
|
|
42
|
+
*
|
|
43
|
+
* Routed through bundler3 via `morphoBorrow`.
|
|
44
|
+
* Validates position health with LLTV buffer (0.5%) using the pre-fetched `positionData`.
|
|
45
|
+
* Computes `minSharePrice` from market borrow state and `slippageTolerance`.
|
|
46
|
+
*
|
|
47
|
+
* When `reallocations` is provided, `reallocateTo` actions are prepended to the bundle,
|
|
48
|
+
* moving liquidity from other markets via the PublicAllocator before borrowing.
|
|
49
|
+
*
|
|
50
|
+
* `getRequirements` returns `morpho.setAuthorization(generalAdapter1, true)` if not yet authorized,
|
|
51
|
+
* since borrowing through bundler3 requires GeneralAdapter1 authorization on Morpho.
|
|
52
|
+
*
|
|
53
|
+
* **Stale `positionData` may cause unexpected health.**
|
|
54
|
+
*
|
|
55
|
+
* @param params - Borrow parameters including pre-fetched `positionData` for health validation.
|
|
56
|
+
* @returns Object with `buildTx` and `getRequirements`.
|
|
57
|
+
*/
|
|
58
|
+
borrow: (params: {
|
|
59
|
+
userAddress: Address;
|
|
60
|
+
amount: bigint;
|
|
61
|
+
positionData: AccrualPosition;
|
|
62
|
+
slippageTolerance?: bigint;
|
|
63
|
+
reallocations?: readonly VaultReallocation[];
|
|
64
|
+
}) => {
|
|
65
|
+
buildTx: () => Readonly<Transaction<MarketV1BorrowAction>>;
|
|
66
|
+
getRequirements: () => Promise<Readonly<Transaction<MorphoAuthorizationAction>>[]>;
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* Prepares a repay transaction.
|
|
70
|
+
*
|
|
71
|
+
* Routed through bundler3 via GeneralAdapter1.
|
|
72
|
+
* Supports two modes via {@link RepayAmountArgs}:
|
|
73
|
+
* - **By assets** (`{ amount }`): repays an exact asset amount (partial repay).
|
|
74
|
+
* - **By shares** (`{ shares }`): repays exact shares (full repay, immune to interest accrual).
|
|
75
|
+
*
|
|
76
|
+
* Computes `maxSharePrice` from market borrow state and `slippageTolerance`.
|
|
77
|
+
*
|
|
78
|
+
* `getRequirements` returns ERC20 approval for loan token to GeneralAdapter1.
|
|
79
|
+
* Does NOT require Morpho authorization (anyone can repay on behalf of anyone).
|
|
80
|
+
*
|
|
81
|
+
* **Shares mode:** `slippageTolerance` also caps `transferAmount`.
|
|
82
|
+
*
|
|
83
|
+
* @param params - Repay parameters including pre-fetched `positionData`.
|
|
84
|
+
* @returns Object with `buildTx` and `getRequirements`.
|
|
85
|
+
*/
|
|
86
|
+
repay: (params: {
|
|
87
|
+
userAddress: Address;
|
|
88
|
+
positionData: AccrualPosition;
|
|
89
|
+
slippageTolerance?: bigint;
|
|
90
|
+
} & RepayAmountArgs) => {
|
|
91
|
+
buildTx: (requirementSignature?: RequirementSignature) => Readonly<Transaction<MarketV1RepayAction>>;
|
|
92
|
+
getRequirements: (params?: {
|
|
93
|
+
useSimplePermit?: boolean;
|
|
94
|
+
}) => Promise<(Readonly<Transaction<ERC20ApprovalAction>> | Requirement)[]>;
|
|
95
|
+
};
|
|
96
|
+
/**
|
|
97
|
+
* Prepares a withdraw-collateral transaction.
|
|
98
|
+
*
|
|
99
|
+
* Direct call to `morpho.withdrawCollateral()` — no bundler, no GeneralAdapter1.
|
|
100
|
+
* The caller (`msg.sender`) must be `onBehalf`.
|
|
101
|
+
* Validates position health after withdrawal using the LLTV buffer.
|
|
102
|
+
*
|
|
103
|
+
* No `getRequirements` — no ERC20 approval or GeneralAdapter1 authorization needed
|
|
104
|
+
* (collateral flows out of Morpho, not in).
|
|
105
|
+
*
|
|
106
|
+
* **No on-chain slippage guard — stale `positionData` risks liquidation.**
|
|
107
|
+
*
|
|
108
|
+
* @param params - Withdraw collateral parameters including pre-fetched `positionData` for health validation.
|
|
109
|
+
* @returns Object with `buildTx`.
|
|
110
|
+
*/
|
|
111
|
+
withdrawCollateral: (params: {
|
|
112
|
+
userAddress: Address;
|
|
113
|
+
amount: bigint;
|
|
114
|
+
positionData: AccrualPosition;
|
|
115
|
+
}) => {
|
|
116
|
+
buildTx: () => Readonly<Transaction<MarketV1WithdrawCollateralAction>>;
|
|
117
|
+
};
|
|
118
|
+
/**
|
|
119
|
+
* Prepares an atomic repay-and-withdraw-collateral transaction.
|
|
120
|
+
*
|
|
121
|
+
* Routed through bundler3. Bundle order: repay FIRST, then withdraw.
|
|
122
|
+
* Validates combined position health: simulates the repay, then checks
|
|
123
|
+
* that the resulting position can sustain the collateral withdrawal.
|
|
124
|
+
*
|
|
125
|
+
* `getRequirements` returns in parallel:
|
|
126
|
+
* - ERC20 approval for loan token to GeneralAdapter1 (for the repay).
|
|
127
|
+
* - `morpho.setAuthorization(generalAdapter1, true)` if not yet authorized (for the withdraw).
|
|
128
|
+
*
|
|
129
|
+
* **Stale `positionData` risks underestimated debt and unsafe withdrawal.**
|
|
130
|
+
*
|
|
131
|
+
* @param params - Combined parameters including pre-fetched `positionData`.
|
|
132
|
+
* @returns Object with `buildTx` and `getRequirements`.
|
|
133
|
+
*/
|
|
134
|
+
repayWithdrawCollateral: (params: {
|
|
135
|
+
userAddress: Address;
|
|
136
|
+
withdrawAmount: bigint;
|
|
137
|
+
positionData: AccrualPosition;
|
|
138
|
+
slippageTolerance?: bigint;
|
|
139
|
+
} & RepayAmountArgs) => {
|
|
140
|
+
buildTx: (requirementSignature?: RequirementSignature) => Readonly<Transaction<MarketV1RepayWithdrawCollateralAction>>;
|
|
141
|
+
getRequirements: (params?: {
|
|
142
|
+
useSimplePermit?: boolean;
|
|
143
|
+
}) => Promise<(Readonly<Transaction<ERC20ApprovalAction>> | Readonly<Transaction<MorphoAuthorizationAction>> | Requirement)[]>;
|
|
144
|
+
};
|
|
145
|
+
/**
|
|
146
|
+
* Prepares an atomic supply-collateral-and-borrow transaction.
|
|
147
|
+
*
|
|
148
|
+
* Routed through the bundler. Validates position health with LLTV buffer
|
|
149
|
+
* to prevent instant liquidation on new positions near the LLTV threshold.
|
|
150
|
+
*
|
|
151
|
+
* When `reallocations` is provided, `reallocateTo` actions are prepended before
|
|
152
|
+
* `morphoBorrow` in the bundle.
|
|
153
|
+
*
|
|
154
|
+
* `getRequirements` returns in parallel:
|
|
155
|
+
* - ERC20 approval or permit for collateral token (to GeneralAdapter1).
|
|
156
|
+
* - `morpho.setAuthorization(generalAdapter1, true)` if adapter is not yet authorized.
|
|
157
|
+
*
|
|
158
|
+
* **Stale `positionData` may cause unexpected health.**
|
|
159
|
+
*
|
|
160
|
+
* @param params - Combined parameters including pre-fetched `positionData` for health validation.
|
|
161
|
+
* @returns Object with `buildTx` and `getRequirements`.
|
|
162
|
+
*/
|
|
163
|
+
supplyCollateralBorrow: (params: {
|
|
164
|
+
userAddress: Address;
|
|
165
|
+
positionData: AccrualPosition;
|
|
166
|
+
borrowAmount: bigint;
|
|
167
|
+
slippageTolerance?: bigint;
|
|
168
|
+
reallocations?: readonly VaultReallocation[];
|
|
169
|
+
} & DepositAmountArgs) => {
|
|
170
|
+
buildTx: (requirementSignature?: RequirementSignature) => Readonly<Transaction<MarketV1SupplyCollateralBorrowAction>>;
|
|
171
|
+
getRequirements: (params?: {
|
|
172
|
+
useSimplePermit?: boolean;
|
|
173
|
+
}) => Promise<(Readonly<Transaction<ERC20ApprovalAction>> | Readonly<Transaction<MorphoAuthorizationAction>> | Requirement)[]>;
|
|
174
|
+
};
|
|
175
|
+
/**
|
|
176
|
+
* Fetches all on-chain data needed to construct a {@link SimulationState}
|
|
177
|
+
* for computing vault reallocations via the public allocator.
|
|
178
|
+
*
|
|
179
|
+
* The returned simulation state can be passed to {@link getReallocations}
|
|
180
|
+
* to compute the `VaultReallocation[]` array for `borrow()` or
|
|
181
|
+
* `supplyCollateralBorrow()`.
|
|
182
|
+
*
|
|
183
|
+
* **Stale data reverts on-chain (fail-safe).**
|
|
184
|
+
*
|
|
185
|
+
* @param params.vaultAddresses - Addresses of MetaMorpho vaults that allocate to this market.
|
|
186
|
+
* @param params.market - The target market data (from {@link getPositionData} or {@link getMarketData}).
|
|
187
|
+
* @param params.block - The block to fetch data at (number and timestamp).
|
|
188
|
+
* @returns A SimulationState populated with all required data.
|
|
189
|
+
*/
|
|
190
|
+
getReallocationData: (params: {
|
|
191
|
+
vaultAddresses: readonly Address[];
|
|
192
|
+
market: Market;
|
|
193
|
+
block: MinimalBlock;
|
|
194
|
+
}) => Promise<SimulationState>;
|
|
195
|
+
/**
|
|
196
|
+
* Computes vault reallocations for a borrow on this market.
|
|
197
|
+
*
|
|
198
|
+
* Uses the shared liquidity algorithm to determine which vaults should
|
|
199
|
+
* reallocate liquidity to this market via the PublicAllocator, based on
|
|
200
|
+
* post-borrow utilization targets.
|
|
201
|
+
*
|
|
202
|
+
* @param params.reallocationData - The current on-chain state (from {@link getReallocationData}).
|
|
203
|
+
* @param params.borrowAmount - The intended borrow amount.
|
|
204
|
+
* @param params.options - Optional reallocation computation options
|
|
205
|
+
* (utilization targets, reallocatable vaults filter, etc.).
|
|
206
|
+
* @returns Array of vault reallocations ready to pass to `borrow()` or
|
|
207
|
+
* `supplyCollateralBorrow()`. Empty array if no reallocation is needed.
|
|
208
|
+
*/
|
|
209
|
+
getReallocations: (params: {
|
|
210
|
+
reallocationData: SimulationState;
|
|
211
|
+
borrowAmount: bigint;
|
|
212
|
+
options?: ReallocationComputeOptions;
|
|
213
|
+
}) => readonly VaultReallocation[];
|
|
214
|
+
}
|
|
215
|
+
export declare class MorphoMarketV1 implements MarketV1Actions {
|
|
216
|
+
private readonly client;
|
|
217
|
+
readonly marketParams: MarketParams;
|
|
218
|
+
private readonly chainId;
|
|
219
|
+
constructor(client: MorphoClientType, marketParams: MarketParams, chainId: number);
|
|
220
|
+
getMarketData(parameters?: FetchParameters): Promise<Market>;
|
|
221
|
+
getPositionData(userAddress: Address, parameters?: FetchParameters): Promise<AccrualPosition>;
|
|
222
|
+
supplyCollateral({ amount, userAddress, nativeAmount, }: {
|
|
223
|
+
userAddress: Address;
|
|
224
|
+
} & DepositAmountArgs): {
|
|
225
|
+
getRequirements: (params?: {
|
|
226
|
+
useSimplePermit?: boolean;
|
|
227
|
+
}) => Promise<(Requirement | Readonly<Transaction<ERC20ApprovalAction>>)[]>;
|
|
228
|
+
buildTx: (requirementSignature?: RequirementSignature) => Readonly<Transaction<MarketV1SupplyCollateralAction>>;
|
|
229
|
+
};
|
|
230
|
+
borrow({ amount, userAddress, positionData, slippageTolerance, reallocations, }: {
|
|
231
|
+
amount: bigint;
|
|
232
|
+
userAddress: Address;
|
|
233
|
+
positionData: AccrualPosition;
|
|
234
|
+
slippageTolerance?: bigint;
|
|
235
|
+
reallocations?: readonly VaultReallocation[];
|
|
236
|
+
}): {
|
|
237
|
+
getRequirements: () => Promise<Readonly<Transaction<MorphoAuthorizationAction>>[]>;
|
|
238
|
+
buildTx: () => Readonly<Transaction<MarketV1BorrowAction>>;
|
|
239
|
+
};
|
|
240
|
+
repay(params: {
|
|
241
|
+
userAddress: Address;
|
|
242
|
+
positionData: AccrualPosition;
|
|
243
|
+
slippageTolerance?: bigint;
|
|
244
|
+
} & RepayAmountArgs): {
|
|
245
|
+
getRequirements: (reqParams?: {
|
|
246
|
+
useSimplePermit?: boolean;
|
|
247
|
+
}) => Promise<(Requirement | Readonly<Transaction<ERC20ApprovalAction>>)[]>;
|
|
248
|
+
buildTx: (requirementSignature?: RequirementSignature) => Readonly<Transaction<MarketV1RepayAction>>;
|
|
249
|
+
};
|
|
250
|
+
withdrawCollateral({ userAddress, amount, positionData, }: {
|
|
251
|
+
userAddress: Address;
|
|
252
|
+
amount: bigint;
|
|
253
|
+
positionData: AccrualPosition;
|
|
254
|
+
}): {
|
|
255
|
+
buildTx: () => Readonly<Transaction<MarketV1WithdrawCollateralAction>>;
|
|
256
|
+
};
|
|
257
|
+
repayWithdrawCollateral(params: {
|
|
258
|
+
userAddress: Address;
|
|
259
|
+
withdrawAmount: bigint;
|
|
260
|
+
positionData: AccrualPosition;
|
|
261
|
+
slippageTolerance?: bigint;
|
|
262
|
+
} & RepayAmountArgs): {
|
|
263
|
+
getRequirements: (reqParams?: {
|
|
264
|
+
useSimplePermit?: boolean;
|
|
265
|
+
}) => Promise<(Requirement | Readonly<Transaction<ERC20ApprovalAction>> | Readonly<Transaction<MorphoAuthorizationAction>>)[]>;
|
|
266
|
+
buildTx: (requirementSignature?: RequirementSignature) => Readonly<Transaction<MarketV1RepayWithdrawCollateralAction>>;
|
|
267
|
+
};
|
|
268
|
+
supplyCollateralBorrow({ amount, userAddress, positionData, borrowAmount, nativeAmount, slippageTolerance, reallocations, }: {
|
|
269
|
+
userAddress: Address;
|
|
270
|
+
positionData: AccrualPosition;
|
|
271
|
+
borrowAmount: bigint;
|
|
272
|
+
slippageTolerance?: bigint;
|
|
273
|
+
reallocations?: readonly VaultReallocation[];
|
|
274
|
+
} & DepositAmountArgs): {
|
|
275
|
+
getRequirements: (params?: {
|
|
276
|
+
useSimplePermit?: boolean;
|
|
277
|
+
}) => Promise<(Requirement | Readonly<Transaction<ERC20ApprovalAction>> | Readonly<Transaction<MorphoAuthorizationAction>>)[]>;
|
|
278
|
+
buildTx: (requirementSignature?: RequirementSignature) => Readonly<Transaction<MarketV1SupplyCollateralBorrowAction>>;
|
|
279
|
+
};
|
|
280
|
+
getReallocationData({ vaultAddresses, market, block, }: {
|
|
281
|
+
vaultAddresses: readonly Address[];
|
|
282
|
+
market: Market;
|
|
283
|
+
block: MinimalBlock;
|
|
284
|
+
}): Promise<SimulationState>;
|
|
285
|
+
getReallocations({ reallocationData, borrowAmount, options, }: {
|
|
286
|
+
reallocationData: SimulationState;
|
|
287
|
+
borrowAmount: bigint;
|
|
288
|
+
options?: ReallocationComputeOptions;
|
|
289
|
+
}): readonly VaultReallocation[];
|
|
290
|
+
}
|