@morpho-org/morpho-sdk 3.1.0 → 3.2.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 +116 -3
- package/lib/cjs/actions/marketV1/index.d.ts +1 -0
- package/lib/cjs/actions/marketV1/index.js +1 -0
- package/lib/cjs/actions/marketV1/refinance.d.ts +117 -0
- package/lib/cjs/actions/marketV1/refinance.js +218 -0
- package/lib/cjs/bundler/actions.d.ts +4 -4
- package/lib/cjs/bundler/actions.js +8 -8
- package/lib/cjs/bundler/types.d.ts +4 -4
- package/lib/cjs/entities/marketV1/marketV1.d.ts +58 -3
- package/lib/cjs/entities/marketV1/marketV1.js +158 -0
- package/lib/cjs/entities/reallocationData.js +3 -0
- package/lib/cjs/helpers/computeReallocations.js +2 -0
- package/lib/cjs/types/action.d.ts +13 -1
- package/lib/cjs/types/error.d.ts +57 -0
- package/lib/cjs/types/error.js +82 -1
- package/lib/esm/actions/marketV1/index.d.ts +1 -0
- package/lib/esm/actions/marketV1/index.js +1 -0
- package/lib/esm/actions/marketV1/refinance.d.ts +117 -0
- package/lib/esm/actions/marketV1/refinance.js +214 -0
- package/lib/esm/bundler/actions.d.ts +4 -4
- package/lib/esm/bundler/actions.js +8 -8
- package/lib/esm/bundler/types.d.ts +4 -4
- package/lib/esm/entities/marketV1/marketV1.d.ts +58 -3
- package/lib/esm/entities/marketV1/marketV1.js +161 -3
- package/lib/esm/entities/reallocationData.js +3 -0
- package/lib/esm/helpers/computeReallocations.js +2 -0
- package/lib/esm/types/action.d.ts +13 -1
- package/lib/esm/types/error.d.ts +57 -0
- package/lib/esm/types/error.js +72 -0
- package/package.json +6 -6
|
@@ -152,6 +152,18 @@ export interface MarketV1RepayWithdrawCollateralAction extends BaseAction<"marke
|
|
|
152
152
|
receiver: Address;
|
|
153
153
|
}> {
|
|
154
154
|
}
|
|
155
|
+
export interface MarketV1RefinanceAction extends BaseAction<"marketV1Refinance", {
|
|
156
|
+
readonly sourceMarket: Hex;
|
|
157
|
+
readonly targetMarket: Hex;
|
|
158
|
+
readonly collateralAmount: bigint;
|
|
159
|
+
readonly borrowAssets: bigint;
|
|
160
|
+
readonly borrowShares: bigint;
|
|
161
|
+
readonly minBorrowSharePrice: bigint;
|
|
162
|
+
readonly maxRepaySharePrice: bigint;
|
|
163
|
+
readonly user: Address;
|
|
164
|
+
readonly reallocationFee: bigint;
|
|
165
|
+
}> {
|
|
166
|
+
}
|
|
155
167
|
/**
|
|
156
168
|
* Enforces that exactly one of `assets` / `shares` is provided.
|
|
157
169
|
*
|
|
@@ -173,7 +185,7 @@ export interface MorphoAuthorizationAction extends BaseAction<"morphoAuthorizati
|
|
|
173
185
|
isAuthorized: boolean;
|
|
174
186
|
}> {
|
|
175
187
|
}
|
|
176
|
-
export type TransactionAction = ERC20ApprovalAction | VaultV2DepositAction | VaultV2WithdrawAction | VaultV2RedeemAction | VaultV2ForceWithdrawAction | VaultV2ForceRedeemAction | VaultV1DepositAction | VaultV1WithdrawAction | VaultV1RedeemAction | VaultV1MigrateToV2Action | MarketV1SupplyAction | MarketV1WithdrawAction | MarketV1SupplyCollateralAction | MarketV1BorrowAction | MarketV1SupplyCollateralBorrowAction | MarketV1RepayAction | MarketV1WithdrawCollateralAction | MarketV1RepayWithdrawCollateralAction | MorphoAuthorizationAction;
|
|
188
|
+
export type TransactionAction = ERC20ApprovalAction | VaultV2DepositAction | VaultV2WithdrawAction | VaultV2RedeemAction | VaultV2ForceWithdrawAction | VaultV2ForceRedeemAction | VaultV1DepositAction | VaultV1WithdrawAction | VaultV1RedeemAction | VaultV1MigrateToV2Action | MarketV1SupplyAction | MarketV1WithdrawAction | MarketV1SupplyCollateralAction | MarketV1BorrowAction | MarketV1SupplyCollateralBorrowAction | MarketV1RepayAction | MarketV1WithdrawCollateralAction | MarketV1RepayWithdrawCollateralAction | MarketV1RefinanceAction | MorphoAuthorizationAction;
|
|
177
189
|
export interface Transaction<TAction extends BaseAction = TransactionAction> {
|
|
178
190
|
readonly to: Address;
|
|
179
191
|
readonly value: bigint;
|
package/lib/esm/types/error.d.ts
CHANGED
|
@@ -375,3 +375,60 @@ export declare class VaultAssetMismatchError extends Error {
|
|
|
375
375
|
export declare class NegativeMinSharePriceError extends Error {
|
|
376
376
|
constructor(vault: Address);
|
|
377
377
|
}
|
|
378
|
+
/** Thrown when a refinance's `borrowShares` argument is negative. */
|
|
379
|
+
export declare class NegativeBorrowSharesError extends Error {
|
|
380
|
+
constructor(market: string);
|
|
381
|
+
}
|
|
382
|
+
/** Thrown when a refinance specifies both `borrowAssets` and `borrowShares` as non-zero (modes are mutually exclusive). */
|
|
383
|
+
export declare class BorrowAmountAndSharesExclusiveError extends Error {
|
|
384
|
+
constructor(market: string);
|
|
385
|
+
}
|
|
386
|
+
/** Thrown when a refinance's `maxRepaySharePrice` slippage bound is negative. */
|
|
387
|
+
export declare class NegativeMaxRepaySharePriceError extends Error {
|
|
388
|
+
constructor(market: string);
|
|
389
|
+
}
|
|
390
|
+
/** Thrown when a refinance has identical source and target market ids (a refinance to the same market is a costly no-op). */
|
|
391
|
+
export declare class RefinanceSameMarketError extends Error {
|
|
392
|
+
constructor(market: string);
|
|
393
|
+
}
|
|
394
|
+
/** Thrown when a refinance's source and target markets do not share the same loan or collateral token. */
|
|
395
|
+
export declare class RefinanceTokenMismatchError extends Error {
|
|
396
|
+
constructor(sourceMarket: string, targetMarket: string);
|
|
397
|
+
}
|
|
398
|
+
/** Thrown when a refinance's `collateralAmount` exceeds the source position's available collateral. */
|
|
399
|
+
export declare class RefinanceExceedsCollateralError extends Error {
|
|
400
|
+
readonly market: string;
|
|
401
|
+
readonly requested: bigint;
|
|
402
|
+
readonly available: bigint;
|
|
403
|
+
constructor(params: {
|
|
404
|
+
market: string;
|
|
405
|
+
requested: bigint;
|
|
406
|
+
available: bigint;
|
|
407
|
+
});
|
|
408
|
+
}
|
|
409
|
+
/** Thrown when a refinance's `borrowShares` exceeds the source position's outstanding borrow shares. */
|
|
410
|
+
export declare class RefinanceExceedsBorrowSharesError extends Error {
|
|
411
|
+
readonly market: string;
|
|
412
|
+
readonly requested: bigint;
|
|
413
|
+
readonly available: bigint;
|
|
414
|
+
constructor(params: {
|
|
415
|
+
market: string;
|
|
416
|
+
requested: bigint;
|
|
417
|
+
available: bigint;
|
|
418
|
+
});
|
|
419
|
+
}
|
|
420
|
+
/** Thrown when a refinance's `borrowAssets` exceeds the source position's outstanding debt assets. */
|
|
421
|
+
export declare class RefinanceExceedsBorrowAssetsError extends Error {
|
|
422
|
+
readonly market: string;
|
|
423
|
+
readonly requested: bigint;
|
|
424
|
+
readonly available: bigint;
|
|
425
|
+
constructor(params: {
|
|
426
|
+
market: string;
|
|
427
|
+
requested: bigint;
|
|
428
|
+
available: bigint;
|
|
429
|
+
});
|
|
430
|
+
}
|
|
431
|
+
/** Thrown when a refinance in shares mode (`borrowShares > 0n`) omits the `borrowAssets` overshoot for the target borrow leg. */
|
|
432
|
+
export declare class RefinanceSharesMissingBorrowAssetsError extends Error {
|
|
433
|
+
constructor(market: string);
|
|
434
|
+
}
|
package/lib/esm/types/error.js
CHANGED
|
@@ -470,3 +470,75 @@ export class NegativeMinSharePriceError extends Error {
|
|
|
470
470
|
super(`Min share price must be non-negative for vault: ${vault}`);
|
|
471
471
|
}
|
|
472
472
|
}
|
|
473
|
+
/** Thrown when a refinance's `borrowShares` argument is negative. */
|
|
474
|
+
export class NegativeBorrowSharesError extends Error {
|
|
475
|
+
constructor(market) {
|
|
476
|
+
super(`Borrow shares must be non-negative for market: ${market}`);
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
/** Thrown when a refinance specifies both `borrowAssets` and `borrowShares` as non-zero (modes are mutually exclusive). */
|
|
480
|
+
export class BorrowAmountAndSharesExclusiveError extends Error {
|
|
481
|
+
constructor(market) {
|
|
482
|
+
super(`Exactly one of borrowAssets or borrowShares must be non-zero for market: ${market}. Both were provided.`);
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
/** Thrown when a refinance's `maxRepaySharePrice` slippage bound is negative. */
|
|
486
|
+
export class NegativeMaxRepaySharePriceError extends Error {
|
|
487
|
+
constructor(market) {
|
|
488
|
+
super(`Max repay share price must be non-negative for market: ${market}`);
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
/** Thrown when a refinance has identical source and target market ids (a refinance to the same market is a costly no-op). */
|
|
492
|
+
export class RefinanceSameMarketError extends Error {
|
|
493
|
+
constructor(market) {
|
|
494
|
+
super(`Refinance source and target market ${market} are identical. Refinance requires a different target market.`);
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
/** Thrown when a refinance's source and target markets do not share the same loan or collateral token. */
|
|
498
|
+
export class RefinanceTokenMismatchError extends Error {
|
|
499
|
+
constructor(sourceMarket, targetMarket) {
|
|
500
|
+
super(`Refinance source market ${sourceMarket} and target market ${targetMarket} must share the same loanToken and collateralToken.`);
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
/** Thrown when a refinance's `collateralAmount` exceeds the source position's available collateral. */
|
|
504
|
+
export class RefinanceExceedsCollateralError extends Error {
|
|
505
|
+
market;
|
|
506
|
+
requested;
|
|
507
|
+
available;
|
|
508
|
+
constructor(params) {
|
|
509
|
+
super(`Refinance collateral amount ${params.requested} exceeds available collateral ${params.available} for market: ${params.market}`);
|
|
510
|
+
this.market = params.market;
|
|
511
|
+
this.requested = params.requested;
|
|
512
|
+
this.available = params.available;
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
/** Thrown when a refinance's `borrowShares` exceeds the source position's outstanding borrow shares. */
|
|
516
|
+
export class RefinanceExceedsBorrowSharesError extends Error {
|
|
517
|
+
market;
|
|
518
|
+
requested;
|
|
519
|
+
available;
|
|
520
|
+
constructor(params) {
|
|
521
|
+
super(`Refinance borrow shares ${params.requested} exceed outstanding borrow shares ${params.available} for market: ${params.market}`);
|
|
522
|
+
this.market = params.market;
|
|
523
|
+
this.requested = params.requested;
|
|
524
|
+
this.available = params.available;
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
/** Thrown when a refinance's `borrowAssets` exceeds the source position's outstanding debt assets. */
|
|
528
|
+
export class RefinanceExceedsBorrowAssetsError extends Error {
|
|
529
|
+
market;
|
|
530
|
+
requested;
|
|
531
|
+
available;
|
|
532
|
+
constructor(params) {
|
|
533
|
+
super(`Refinance borrow assets ${params.requested} exceed outstanding debt assets ${params.available} for market: ${params.market}`);
|
|
534
|
+
this.market = params.market;
|
|
535
|
+
this.requested = params.requested;
|
|
536
|
+
this.available = params.available;
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
/** Thrown when a refinance in shares mode (`borrowShares > 0n`) omits the `borrowAssets` overshoot for the target borrow leg. */
|
|
540
|
+
export class RefinanceSharesMissingBorrowAssetsError extends Error {
|
|
541
|
+
constructor(market) {
|
|
542
|
+
super(`Refinance shares mode requires a positive borrowAssets overshoot for the target borrow leg (market: ${market}).`);
|
|
543
|
+
}
|
|
544
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@morpho-org/morpho-sdk",
|
|
3
3
|
"description": "Abstraction layer for Morpho's complexity.",
|
|
4
|
-
"version": "3.
|
|
4
|
+
"version": "3.2.0",
|
|
5
5
|
"author": "Morpho Association <contact@morpho.org>",
|
|
6
6
|
"contributors": [
|
|
7
7
|
"Foulks-Plb <https://x.com/FoulkPlb>"
|
|
@@ -137,9 +137,9 @@
|
|
|
137
137
|
],
|
|
138
138
|
"dependencies": {
|
|
139
139
|
"zod": "^4.4.3",
|
|
140
|
-
"@morpho-org/blue-sdk": "^6.0
|
|
141
|
-
"@morpho-org/
|
|
142
|
-
"@morpho-org/
|
|
140
|
+
"@morpho-org/blue-sdk": "^6.1.0",
|
|
141
|
+
"@morpho-org/morpho-ts": "^2.6.0",
|
|
142
|
+
"@morpho-org/blue-sdk-viem": "^5.1.0"
|
|
143
143
|
},
|
|
144
144
|
"peerDependencies": {
|
|
145
145
|
"viem": "^2.0.0"
|
|
@@ -150,8 +150,8 @@
|
|
|
150
150
|
"typescript": "^6.0.3",
|
|
151
151
|
"viem": "^2.50.4",
|
|
152
152
|
"vitest": "^4.1.7",
|
|
153
|
-
"@morpho-org/bundler-sdk-viem": "^5.0.
|
|
154
|
-
"@morpho-org/simulation-sdk": "^4.0.
|
|
153
|
+
"@morpho-org/bundler-sdk-viem": "^5.0.3",
|
|
154
|
+
"@morpho-org/simulation-sdk": "^4.0.3",
|
|
155
155
|
"@morpho-org/test": "^2.8.1"
|
|
156
156
|
},
|
|
157
157
|
"scripts": {
|