@morpho-org/blue-sdk 1.7.1 → 1.7.3
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/lib/market/Market.d.ts +6 -6
- package/lib/market/Market.js +7 -7
- package/lib/market/MarketConfig.d.ts +3 -3
- package/lib/market/MarketConfig.js +15 -13
- package/lib/market/MarketUtils.js +1 -1
- package/lib/maths/AdaptiveCurveIrmLib.js +4 -1
- package/lib/position/Position.d.ts +12 -8
- package/lib/position/Position.js +8 -4
- package/lib/vault/Vault.d.ts +6 -2
- package/lib/vault/Vault.js +7 -6
- package/package.json +5 -5
package/lib/market/Market.d.ts
CHANGED
|
@@ -114,25 +114,25 @@ export declare class Market implements InputMarket {
|
|
|
114
114
|
get borrowApy(): bigint;
|
|
115
115
|
/**
|
|
116
116
|
* Returns a new market derived from this market, whose interest has been accrued up to the given timestamp.
|
|
117
|
-
* @param timestamp The timestamp at which to accrue interest. Must be greater than or equal to `lastUpdate`.
|
|
117
|
+
* @param timestamp The timestamp at which to accrue interest. Must be greater than or equal to `lastUpdate`. Defaults to `lastUpdate` (returns a copy of the market).
|
|
118
118
|
*/
|
|
119
|
-
accrueInterest(timestamp
|
|
120
|
-
supply(assets: bigint, shares: bigint, timestamp?:
|
|
119
|
+
accrueInterest(timestamp?: BigIntish): Market;
|
|
120
|
+
supply(assets: bigint, shares: bigint, timestamp?: BigIntish): {
|
|
121
121
|
market: Market;
|
|
122
122
|
assets: bigint;
|
|
123
123
|
shares: bigint;
|
|
124
124
|
};
|
|
125
|
-
withdraw(assets: bigint, shares: bigint, timestamp?:
|
|
125
|
+
withdraw(assets: bigint, shares: bigint, timestamp?: BigIntish): {
|
|
126
126
|
market: Market;
|
|
127
127
|
assets: bigint;
|
|
128
128
|
shares: bigint;
|
|
129
129
|
};
|
|
130
|
-
borrow(assets: bigint, shares: bigint, timestamp?:
|
|
130
|
+
borrow(assets: bigint, shares: bigint, timestamp?: BigIntish): {
|
|
131
131
|
market: Market;
|
|
132
132
|
assets: bigint;
|
|
133
133
|
shares: bigint;
|
|
134
134
|
};
|
|
135
|
-
repay(assets: bigint, shares: bigint, timestamp?:
|
|
135
|
+
repay(assets: bigint, shares: bigint, timestamp?: BigIntish): {
|
|
136
136
|
market: Market;
|
|
137
137
|
assets: bigint;
|
|
138
138
|
shares: bigint;
|
package/lib/market/Market.js
CHANGED
|
@@ -129,15 +129,15 @@ class Market {
|
|
|
129
129
|
}
|
|
130
130
|
/**
|
|
131
131
|
* Returns a new market derived from this market, whose interest has been accrued up to the given timestamp.
|
|
132
|
-
* @param timestamp The timestamp at which to accrue interest. Must be greater than or equal to `lastUpdate`.
|
|
132
|
+
* @param timestamp The timestamp at which to accrue interest. Must be greater than or equal to `lastUpdate`. Defaults to `lastUpdate` (returns a copy of the market).
|
|
133
133
|
*/
|
|
134
|
-
accrueInterest(timestamp) {
|
|
134
|
+
accrueInterest(timestamp = this.lastUpdate) {
|
|
135
135
|
timestamp = BigInt(timestamp);
|
|
136
136
|
const elapsed = timestamp - this.lastUpdate;
|
|
137
137
|
if (elapsed < 0n)
|
|
138
138
|
throw new errors_1.BlueErrors.InvalidInterestAccrual(this.id, timestamp, this.lastUpdate);
|
|
139
139
|
if (elapsed === 0n)
|
|
140
|
-
return this;
|
|
140
|
+
return new Market(this);
|
|
141
141
|
let borrowRate = 0n;
|
|
142
142
|
let { rateAtTarget } = this;
|
|
143
143
|
if (rateAtTarget != null) {
|
|
@@ -155,7 +155,7 @@ class Market {
|
|
|
155
155
|
rateAtTarget,
|
|
156
156
|
});
|
|
157
157
|
}
|
|
158
|
-
supply(assets, shares, timestamp
|
|
158
|
+
supply(assets, shares, timestamp) {
|
|
159
159
|
if (assets === 0n && shares === 0n)
|
|
160
160
|
throw new errors_1.BlueErrors.InconsistentInput();
|
|
161
161
|
const market = this.accrueInterest(timestamp);
|
|
@@ -167,7 +167,7 @@ class Market {
|
|
|
167
167
|
market.totalSupplyShares += shares;
|
|
168
168
|
return { market, assets, shares };
|
|
169
169
|
}
|
|
170
|
-
withdraw(assets, shares, timestamp
|
|
170
|
+
withdraw(assets, shares, timestamp) {
|
|
171
171
|
if (assets === 0n && shares === 0n)
|
|
172
172
|
throw new errors_1.BlueErrors.InconsistentInput();
|
|
173
173
|
const market = this.accrueInterest(timestamp);
|
|
@@ -181,7 +181,7 @@ class Market {
|
|
|
181
181
|
throw new errors_1.BlueErrors.InsufficientLiquidity(market.id);
|
|
182
182
|
return { market, assets, shares };
|
|
183
183
|
}
|
|
184
|
-
borrow(assets, shares, timestamp
|
|
184
|
+
borrow(assets, shares, timestamp) {
|
|
185
185
|
if (assets === 0n && shares === 0n)
|
|
186
186
|
throw new errors_1.BlueErrors.InconsistentInput();
|
|
187
187
|
const market = this.accrueInterest(timestamp);
|
|
@@ -195,7 +195,7 @@ class Market {
|
|
|
195
195
|
throw new errors_1.BlueErrors.InsufficientLiquidity(market.id);
|
|
196
196
|
return { market, assets, shares };
|
|
197
197
|
}
|
|
198
|
-
repay(assets, shares, timestamp
|
|
198
|
+
repay(assets, shares, timestamp) {
|
|
199
199
|
if (assets === 0n && shares === 0n)
|
|
200
200
|
throw new errors_1.BlueErrors.InconsistentInput();
|
|
201
201
|
const market = this.accrueInterest(timestamp);
|
|
@@ -40,13 +40,13 @@ export declare class MarketConfig implements MarketParams {
|
|
|
40
40
|
* The market's liquidation Loan-To-Value (scaled by WAD).
|
|
41
41
|
*/
|
|
42
42
|
readonly lltv: bigint;
|
|
43
|
-
constructor({ collateralToken, loanToken, oracle, irm, lltv }: MarketParams);
|
|
44
43
|
/**
|
|
45
44
|
* The market's hex-encoded id, defined as the hash of the market params.
|
|
46
45
|
*/
|
|
47
|
-
|
|
46
|
+
readonly id: MarketId;
|
|
48
47
|
/**
|
|
49
48
|
* The market's liquidation incentive factor.
|
|
50
49
|
*/
|
|
51
|
-
|
|
50
|
+
readonly liquidationIncentiveFactor: bigint;
|
|
51
|
+
constructor(params: MarketParams);
|
|
52
52
|
}
|
|
@@ -50,25 +50,27 @@ class MarketConfig {
|
|
|
50
50
|
* The market's liquidation Loan-To-Value (scaled by WAD).
|
|
51
51
|
*/
|
|
52
52
|
lltv;
|
|
53
|
-
constructor({ collateralToken, loanToken, oracle, irm, lltv }) {
|
|
54
|
-
this.collateralToken = collateralToken;
|
|
55
|
-
this.loanToken = loanToken;
|
|
56
|
-
this.oracle = oracle;
|
|
57
|
-
this.irm = irm;
|
|
58
|
-
this.lltv = BigInt(lltv);
|
|
59
|
-
MarketConfig._CACHE[this.id] = this;
|
|
60
|
-
}
|
|
61
53
|
/**
|
|
62
54
|
* The market's hex-encoded id, defined as the hash of the market params.
|
|
63
55
|
*/
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}
|
|
56
|
+
// Cached because params are readonly.
|
|
57
|
+
id;
|
|
67
58
|
/**
|
|
68
59
|
* The market's liquidation incentive factor.
|
|
69
60
|
*/
|
|
70
|
-
|
|
71
|
-
|
|
61
|
+
// Cached because lltv is readonly.
|
|
62
|
+
liquidationIncentiveFactor;
|
|
63
|
+
constructor(params) {
|
|
64
|
+
const { collateralToken, loanToken, oracle, irm, lltv } = params;
|
|
65
|
+
this.collateralToken = collateralToken;
|
|
66
|
+
this.loanToken = loanToken;
|
|
67
|
+
this.oracle = oracle;
|
|
68
|
+
this.irm = irm;
|
|
69
|
+
this.lltv = BigInt(lltv);
|
|
70
|
+
this.id = MarketUtils_1.MarketUtils.getMarketId(params);
|
|
71
|
+
this.liquidationIncentiveFactor =
|
|
72
|
+
MarketUtils_1.MarketUtils.getLiquidationIncentiveFactor(params);
|
|
73
|
+
MarketConfig._CACHE[this.id] = this;
|
|
72
74
|
}
|
|
73
75
|
}
|
|
74
76
|
exports.MarketConfig = MarketConfig;
|
|
@@ -22,7 +22,7 @@ var MarketUtils;
|
|
|
22
22
|
market.collateralToken.substring(2).toLowerCase().padStart(64, "0") +
|
|
23
23
|
market.oracle.substring(2).padStart(64, "0") +
|
|
24
24
|
market.irm.substring(2).toLowerCase().padStart(64, "0") +
|
|
25
|
-
market.lltv.toString(16).padStart(64, "0")).toString("hex")}`;
|
|
25
|
+
BigInt(market.lltv).toString(16).padStart(64, "0")).toString("hex")}`;
|
|
26
26
|
}
|
|
27
27
|
MarketUtils.getMarketId = getMarketId;
|
|
28
28
|
/**
|
|
@@ -121,8 +121,11 @@ var AdaptiveCurveIrmLib;
|
|
|
121
121
|
rateAtTarget = BigInt(rateAtTarget);
|
|
122
122
|
if (borrowRate >= rateAtTarget) {
|
|
123
123
|
const maxBorrowRate = MathLib_1.MathLib.wMulDown(rateAtTarget, AdaptiveCurveIrmLib.CURVE_STEEPNESS);
|
|
124
|
+
const diffToMaxBorrowRate = maxBorrowRate - rateAtTarget;
|
|
125
|
+
if (diffToMaxBorrowRate === 0n)
|
|
126
|
+
return MathLib_1.MathLib.WAD;
|
|
124
127
|
return MathLib_1.MathLib.min(MathLib_1.MathLib.WAD, AdaptiveCurveIrmLib.TARGET_UTILIZATION +
|
|
125
|
-
MathLib_1.MathLib.mulDivDown(MathLib_1.MathLib.WAD - AdaptiveCurveIrmLib.TARGET_UTILIZATION, borrowRate - rateAtTarget,
|
|
128
|
+
MathLib_1.MathLib.mulDivDown(MathLib_1.MathLib.WAD - AdaptiveCurveIrmLib.TARGET_UTILIZATION, borrowRate - rateAtTarget, diffToMaxBorrowRate));
|
|
126
129
|
}
|
|
127
130
|
const minBorrowRate = MathLib_1.MathLib.wDivDown(rateAtTarget, AdaptiveCurveIrmLib.CURVE_STEEPNESS);
|
|
128
131
|
return MathLib_1.MathLib.max(0n, MathLib_1.MathLib.mulDivDown(AdaptiveCurveIrmLib.TARGET_UTILIZATION, borrowRate - minBorrowRate, rateAtTarget - minBorrowRate));
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Market } from "../market";
|
|
2
|
-
import { Address, MarketId } from "../types";
|
|
2
|
+
import { Address, BigIntish, MarketId } from "../types";
|
|
3
3
|
export interface InputPosition {
|
|
4
4
|
user: Address;
|
|
5
5
|
marketId: MarketId;
|
|
@@ -91,25 +91,29 @@ export declare class AccrualPosition extends Position implements InputAccrualPos
|
|
|
91
91
|
get borrowCapacityLimit(): import("../market").CapacityLimit;
|
|
92
92
|
get withdrawCapacityLimit(): import("../market").CapacityLimit;
|
|
93
93
|
get withdrawCollateralCapacityLimit(): import("../market").CapacityLimit;
|
|
94
|
-
|
|
95
|
-
|
|
94
|
+
/**
|
|
95
|
+
* Returns a new position derived from this position, whose interest has been accrued up to the given timestamp.
|
|
96
|
+
* @param timestamp The timestamp at which to accrue interest. Must be greater than or equal to the market's `lastUpdate`.
|
|
97
|
+
*/
|
|
98
|
+
accrueInterest(timestamp?: BigIntish): AccrualPosition;
|
|
99
|
+
supply(assets: bigint, shares: bigint, timestamp?: BigIntish): {
|
|
96
100
|
position: AccrualPosition;
|
|
97
101
|
assets: bigint;
|
|
98
102
|
shares: bigint;
|
|
99
103
|
};
|
|
100
|
-
withdraw(assets: bigint, shares: bigint, timestamp?:
|
|
104
|
+
withdraw(assets: bigint, shares: bigint, timestamp?: BigIntish): {
|
|
101
105
|
position: AccrualPosition;
|
|
102
106
|
assets: bigint;
|
|
103
107
|
shares: bigint;
|
|
104
108
|
};
|
|
105
|
-
supplyCollateral(assets: bigint
|
|
106
|
-
withdrawCollateral(assets: bigint, timestamp?:
|
|
107
|
-
borrow(assets: bigint, shares: bigint, timestamp?:
|
|
109
|
+
supplyCollateral(assets: bigint): AccrualPosition;
|
|
110
|
+
withdrawCollateral(assets: bigint, timestamp?: BigIntish): AccrualPosition;
|
|
111
|
+
borrow(assets: bigint, shares: bigint, timestamp?: BigIntish): {
|
|
108
112
|
position: AccrualPosition;
|
|
109
113
|
assets: bigint;
|
|
110
114
|
shares: bigint;
|
|
111
115
|
};
|
|
112
|
-
repay(assets: bigint, shares: bigint, timestamp?:
|
|
116
|
+
repay(assets: bigint, shares: bigint, timestamp?: BigIntish): {
|
|
113
117
|
position: AccrualPosition;
|
|
114
118
|
assets: bigint;
|
|
115
119
|
shares: bigint;
|
package/lib/position/Position.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AccrualPosition = exports.Position = void 0;
|
|
4
4
|
const errors_1 = require("../errors");
|
|
5
|
+
const market_1 = require("../market");
|
|
5
6
|
class Position {
|
|
6
7
|
/**
|
|
7
8
|
* The user holding this position.
|
|
@@ -126,6 +127,10 @@ class AccrualPosition extends Position {
|
|
|
126
127
|
get withdrawCollateralCapacityLimit() {
|
|
127
128
|
return this.market.getWithdrawCollateralCapacityLimit(this);
|
|
128
129
|
}
|
|
130
|
+
/**
|
|
131
|
+
* Returns a new position derived from this position, whose interest has been accrued up to the given timestamp.
|
|
132
|
+
* @param timestamp The timestamp at which to accrue interest. Must be greater than or equal to the market's `lastUpdate`.
|
|
133
|
+
*/
|
|
129
134
|
accrueInterest(timestamp) {
|
|
130
135
|
return new AccrualPosition(this, this.market.accrueInterest(timestamp));
|
|
131
136
|
}
|
|
@@ -151,12 +156,11 @@ class AccrualPosition extends Position {
|
|
|
151
156
|
shares,
|
|
152
157
|
};
|
|
153
158
|
}
|
|
154
|
-
supplyCollateral(assets
|
|
155
|
-
const market = this.market.accrueInterest(timestamp);
|
|
159
|
+
supplyCollateral(assets) {
|
|
156
160
|
this.collateral += assets;
|
|
157
|
-
return new AccrualPosition(this, market);
|
|
161
|
+
return new AccrualPosition(this, new market_1.Market(this.market));
|
|
158
162
|
}
|
|
159
|
-
withdrawCollateral(assets, timestamp
|
|
163
|
+
withdrawCollateral(assets, timestamp) {
|
|
160
164
|
const market = this.market.accrueInterest(timestamp);
|
|
161
165
|
this.collateral -= assets;
|
|
162
166
|
if (this.collateral < 0n)
|
package/lib/vault/Vault.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { CapacityLimit } from "../market";
|
|
2
2
|
import { RoundingDirection } from "../maths";
|
|
3
3
|
import { VaultToken } from "../token";
|
|
4
|
-
import { Address, MarketId } from "../types";
|
|
4
|
+
import { Address, BigIntish, MarketId } from "../types";
|
|
5
5
|
import { VaultConfig } from "./VaultConfig";
|
|
6
6
|
import { InputVaultMarketAllocation, VaultMarketAllocation } from "./VaultMarketAllocation";
|
|
7
7
|
export interface Pending<T> {
|
|
@@ -158,5 +158,9 @@ export declare class AccrualVault extends Vault implements InputAccrualVault {
|
|
|
158
158
|
getAllocationProportion(marketId: MarketId): bigint;
|
|
159
159
|
getDepositCapacityLimit(assets: bigint): CapacityLimit;
|
|
160
160
|
getWithdrawCapacityLimit(shares: bigint): CapacityLimit;
|
|
161
|
-
|
|
161
|
+
/**
|
|
162
|
+
* Returns a new vault derived from this vault, whose interest has been accrued up to the given timestamp.
|
|
163
|
+
* @param timestamp The timestamp at which to accrue interest. Must be greater than or equal to each of the vault's market's `lastUpdate`.
|
|
164
|
+
*/
|
|
165
|
+
accrueInterest(timestamp: BigIntish): AccrualVault;
|
|
162
166
|
}
|
package/lib/vault/Vault.js
CHANGED
|
@@ -135,12 +135,9 @@ class AccrualVault extends Vault {
|
|
|
135
135
|
withdrawQueue: allocations.map(({ position }) => position.market.id),
|
|
136
136
|
totalAssets: allocations.reduce((total, { position }) => total + position.supplyAssets, 0n),
|
|
137
137
|
});
|
|
138
|
-
this.allocations = new Map(allocations.map((
|
|
139
|
-
position.market.id,
|
|
140
|
-
new VaultMarketAllocation_1.VaultMarketAllocation(
|
|
141
|
-
config,
|
|
142
|
-
position,
|
|
143
|
-
}),
|
|
138
|
+
this.allocations = new Map(allocations.map((allocation) => [
|
|
139
|
+
allocation.position.market.id,
|
|
140
|
+
new VaultMarketAllocation_1.VaultMarketAllocation(allocation),
|
|
144
141
|
]));
|
|
145
142
|
this.collateralAllocations = new Map();
|
|
146
143
|
for (const { marketId, position } of this.allocations.values()) {
|
|
@@ -216,6 +213,10 @@ class AccrualVault extends Vault {
|
|
|
216
213
|
limiter: market_1.CapacityLimitReason.balance,
|
|
217
214
|
};
|
|
218
215
|
}
|
|
216
|
+
/**
|
|
217
|
+
* Returns a new vault derived from this vault, whose interest has been accrued up to the given timestamp.
|
|
218
|
+
* @param timestamp The timestamp at which to accrue interest. Must be greater than or equal to each of the vault's market's `lastUpdate`.
|
|
219
|
+
*/
|
|
219
220
|
accrueInterest(timestamp) {
|
|
220
221
|
const vault = new AccrualVault(this, Array.from(this.allocations.values(), ({ config, position }) => ({
|
|
221
222
|
config,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@morpho-org/blue-sdk",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.3",
|
|
4
4
|
"author": "Morpho Association <contact@morpho.org>",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
"keccak256": "^1.0.6"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
|
-
"@morpho-org/morpho-test": "^1.7.
|
|
20
|
-
"@morpho-org/morpho-ts": "^1.7.
|
|
19
|
+
"@morpho-org/morpho-test": "^1.7.3",
|
|
20
|
+
"@morpho-org/morpho-ts": "^1.7.3",
|
|
21
21
|
"@types/jest": "^29.5.12",
|
|
22
22
|
"@types/node": "^22.1.0",
|
|
23
23
|
"jest": "^29.7.0",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"typescript": "^5.4.5"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
28
|
-
"@morpho-org/morpho-ts": "^1.7.
|
|
28
|
+
"@morpho-org/morpho-ts": "^1.7.3"
|
|
29
29
|
},
|
|
30
30
|
"publishConfig": {
|
|
31
31
|
"access": "public"
|
|
@@ -49,5 +49,5 @@
|
|
|
49
49
|
],
|
|
50
50
|
"preset": "ts-jest"
|
|
51
51
|
},
|
|
52
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "9084b3dbc30b38d90bb118f7e503110ba148eb51"
|
|
53
53
|
}
|