@morpho-dev/router 0.7.1 → 0.8.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/dist/cli.js +441 -141
- package/dist/drizzle/migrations/0000_setup_single_migration_folder.sql +64 -64
- package/dist/drizzle/migrations/0001_add-trigger-for-consumed-events.sql +5 -5
- package/dist/drizzle/migrations/0002_insert-status-code.sql +1 -1
- package/dist/drizzle/migrations/0003_update-triggers-for-consumed-events.sql +1 -1
- package/dist/drizzle/migrations/0004_drop-status-offers-foreign-key-constraint.sql +1 -1
- package/dist/drizzle/migrations/0005_add-index-to-boost-group-query-and-offer-hash.sql +1 -1
- package/dist/drizzle/migrations/0006_add-callbacks-and-positions-relations.sql +11 -11
- package/dist/drizzle/migrations/0008_validation.sql +10 -10
- package/dist/drizzle/migrations/0009_add-transfers-table.sql +4 -4
- package/dist/drizzle/migrations/0010_add-price.sql +1 -1
- package/dist/drizzle/migrations/0011_nullable-callback-amount.sql +1 -1
- package/dist/drizzle/migrations/0012_add-position-asset.sql +1 -1
- package/dist/drizzle/migrations/0013_remove-depecrated-domains.sql +13 -13
- package/dist/drizzle/migrations/0014_rename-offers-v2-into-offers.sql +19 -19
- package/dist/drizzle/migrations/0015_add-lots-table.sql +3 -3
- package/dist/drizzle/migrations/0016_merkle-metadata.sql +7 -7
- package/dist/drizzle/migrations/0017_dusty_the_hunter.sql +1 -1
- package/dist/drizzle/migrations/0018_add_chain_collector_constraints.sql +3 -3
- package/dist/drizzle/migrations/0019_add-obligation-units-shares.sql +2 -2
- package/dist/drizzle/migrations/0020_add-session.sql +1 -1
- package/dist/drizzle/migrations/0021_drop_chain_collector_epoch_indexes.sql +2 -2
- package/dist/drizzle/migrations/0021_migrate-rate-to-price.sql +6 -6
- package/dist/drizzle/migrations/0022_consolidate-price.sql +5 -5
- package/dist/drizzle/migrations/0023_remove-block-number-for-collaterals.sql +1 -1
- package/dist/drizzle/migrations/0024_add-obligation-id-to-lots.sql +8 -0
- package/dist/drizzle/migrations/0025_rename-price-to-tick.sql +202 -0
- package/dist/drizzle/migrations/meta/0000_snapshot.json +48 -48
- package/dist/drizzle/migrations/meta/0001_snapshot.json +48 -48
- package/dist/drizzle/migrations/meta/0002_snapshot.json +48 -48
- package/dist/drizzle/migrations/meta/0003_snapshot.json +48 -48
- package/dist/drizzle/migrations/meta/0004_snapshot.json +47 -47
- package/dist/drizzle/migrations/meta/0005_snapshot.json +47 -47
- package/dist/drizzle/migrations/meta/0006_snapshot.json +61 -61
- package/dist/drizzle/migrations/meta/0008_snapshot.json +62 -62
- package/dist/drizzle/migrations/meta/0009_snapshot.json +66 -66
- package/dist/drizzle/migrations/meta/0010_snapshot.json +66 -66
- package/dist/drizzle/migrations/meta/0013_snapshot.json +48 -48
- package/dist/drizzle/migrations/meta/0014_snapshot.json +48 -48
- package/dist/drizzle/migrations/meta/0015_snapshot.json +52 -52
- package/dist/drizzle/migrations/meta/0016_snapshot.json +61 -61
- package/dist/drizzle/migrations/meta/0017_snapshot.json +61 -61
- package/dist/drizzle/migrations/meta/0018_snapshot.json +62 -62
- package/dist/drizzle/migrations/meta/0019_snapshot.json +62 -62
- package/dist/drizzle/migrations/meta/0023_snapshot.json +62 -62
- package/dist/drizzle/migrations/meta/0024_snapshot.json +1448 -0
- package/dist/drizzle/migrations/meta/0025_snapshot.json +1448 -0
- package/dist/drizzle/migrations/meta/_journal.json +14 -0
- package/dist/evm/bytecode/erc20.txt +1 -1
- package/dist/evm/bytecode/morpho.txt +1 -1
- package/dist/evm/bytecode/multicall3.txt +1 -1
- package/dist/evm/bytecode/oracle.txt +1 -1
- package/dist/evm/bytecode/vault.txt +1 -1
- package/dist/index.browser.d.mts +1157 -81
- package/dist/index.browser.d.mts.map +1 -1
- package/dist/index.browser.d.ts +1157 -81
- package/dist/index.browser.d.ts.map +1 -1
- package/dist/index.browser.js +371 -151
- package/dist/index.browser.js.map +1 -1
- package/dist/index.browser.mjs +366 -152
- package/dist/index.browser.mjs.map +1 -1
- package/dist/index.node.d.mts +1196 -70
- package/dist/index.node.d.mts.map +1 -1
- package/dist/index.node.d.ts +1196 -70
- package/dist/index.node.d.ts.map +1 -1
- package/dist/index.node.js +491 -145
- package/dist/index.node.js.map +1 -1
- package/dist/index.node.mjs +486 -146
- package/dist/index.node.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.browser.js
CHANGED
|
@@ -52,11 +52,191 @@ let openapi_metadata_decorators = require("openapi-metadata/decorators");
|
|
|
52
52
|
let openapi_fetch = require("openapi-fetch");
|
|
53
53
|
openapi_fetch = __toESM(openapi_fetch);
|
|
54
54
|
|
|
55
|
+
//#region \0@oxc-project+runtime@0.110.0/helpers/typeof.js
|
|
56
|
+
function _typeof(o) {
|
|
57
|
+
"@babel/helpers - typeof";
|
|
58
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
59
|
+
return typeof o;
|
|
60
|
+
} : function(o) {
|
|
61
|
+
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
62
|
+
}, _typeof(o);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
//#endregion
|
|
66
|
+
//#region \0@oxc-project+runtime@0.110.0/helpers/toPrimitive.js
|
|
67
|
+
function toPrimitive(t, r) {
|
|
68
|
+
if ("object" != _typeof(t) || !t) return t;
|
|
69
|
+
var e = t[Symbol.toPrimitive];
|
|
70
|
+
if (void 0 !== e) {
|
|
71
|
+
var i = e.call(t, r || "default");
|
|
72
|
+
if ("object" != _typeof(i)) return i;
|
|
73
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
74
|
+
}
|
|
75
|
+
return ("string" === r ? String : Number)(t);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
//#endregion
|
|
79
|
+
//#region \0@oxc-project+runtime@0.110.0/helpers/toPropertyKey.js
|
|
80
|
+
function toPropertyKey(t) {
|
|
81
|
+
var i = toPrimitive(t, "string");
|
|
82
|
+
return "symbol" == _typeof(i) ? i : i + "";
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
//#endregion
|
|
86
|
+
//#region \0@oxc-project+runtime@0.110.0/helpers/defineProperty.js
|
|
87
|
+
function _defineProperty(e, r, t) {
|
|
88
|
+
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
89
|
+
value: t,
|
|
90
|
+
enumerable: !0,
|
|
91
|
+
configurable: !0,
|
|
92
|
+
writable: !0
|
|
93
|
+
}) : e[r] = t, e;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
//#endregion
|
|
97
|
+
//#region src/utils/Errors.ts
|
|
98
|
+
var Errors_exports = /* @__PURE__ */ __exportAll({
|
|
99
|
+
BaseError: () => BaseError,
|
|
100
|
+
ReorgError: () => ReorgError
|
|
101
|
+
});
|
|
102
|
+
/**
|
|
103
|
+
* Base error class inherited by all errors thrown by mempool.
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* ```ts
|
|
107
|
+
* import { Errors } from 'mempool'
|
|
108
|
+
* throw new Errors.BaseError('An error occurred')
|
|
109
|
+
* ```
|
|
110
|
+
*/
|
|
111
|
+
var BaseError = class BaseError extends Error {
|
|
112
|
+
constructor(shortMessage, options = {}) {
|
|
113
|
+
const details = (() => {
|
|
114
|
+
if (options.cause instanceof BaseError) {
|
|
115
|
+
if (options.cause.details) return options.cause.details;
|
|
116
|
+
if (options.cause.shortMessage) return options.cause.shortMessage;
|
|
117
|
+
}
|
|
118
|
+
if (options.cause && "details" in options.cause && typeof options.cause.details === "string") return options.cause.details;
|
|
119
|
+
if (options.cause?.message) return options.cause.message;
|
|
120
|
+
return options.details;
|
|
121
|
+
})();
|
|
122
|
+
const message = [
|
|
123
|
+
shortMessage || "An error occurred.",
|
|
124
|
+
...options.metaMessages ? ["", ...options.metaMessages] : [],
|
|
125
|
+
...details ? ["", details ? `Details: ${details}` : void 0] : []
|
|
126
|
+
].filter((x) => typeof x === "string").join("\n");
|
|
127
|
+
super(message, options.cause ? { cause: options.cause } : void 0);
|
|
128
|
+
_defineProperty(this, "details", void 0);
|
|
129
|
+
_defineProperty(this, "shortMessage", void 0);
|
|
130
|
+
_defineProperty(this, "cause", void 0);
|
|
131
|
+
_defineProperty(this, "name", "BaseError");
|
|
132
|
+
this.cause = options.cause;
|
|
133
|
+
this.details = details;
|
|
134
|
+
this.shortMessage = shortMessage;
|
|
135
|
+
}
|
|
136
|
+
walk(fn) {
|
|
137
|
+
return walk(this, fn);
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
/** @internal */
|
|
141
|
+
function walk(err, fn) {
|
|
142
|
+
if (fn?.(err)) return err;
|
|
143
|
+
if (err && typeof err === "object" && "cause" in err && err.cause) return walk(err.cause, fn);
|
|
144
|
+
return fn ? null : err;
|
|
145
|
+
}
|
|
146
|
+
var ReorgError = class extends BaseError {
|
|
147
|
+
constructor(blockNumber) {
|
|
148
|
+
super(`Reorg detected at block number ${blockNumber}`);
|
|
149
|
+
_defineProperty(this, "name", "ReorgError");
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
//#endregion
|
|
154
|
+
//#region src/core/Tick.ts
|
|
155
|
+
var Tick_exports = /* @__PURE__ */ __exportAll({
|
|
156
|
+
InvalidPriceError: () => InvalidPriceError,
|
|
157
|
+
InvalidTickError: () => InvalidTickError,
|
|
158
|
+
MAX_PRICE: () => MAX_PRICE,
|
|
159
|
+
TICK_RANGE: () => TICK_RANGE,
|
|
160
|
+
priceToTick: () => priceToTick,
|
|
161
|
+
tickToPrice: () => tickToPrice
|
|
162
|
+
});
|
|
163
|
+
/** ln(1 + 0.025), scaled by 1e18. Matches TickLib onchain constant. */
|
|
164
|
+
const LN_ONE_PLUS_DELTA = 24692612590371501n;
|
|
165
|
+
/** ln(2), scaled by 1e18. Matches TickLib onchain constant. */
|
|
166
|
+
const LN2 = 693147180559945309n;
|
|
167
|
+
const WAD$1 = 10n ** 18n;
|
|
168
|
+
const WAD_SQUARED = 10n ** 36n;
|
|
169
|
+
const PRICE_STEP = 10n ** 13n;
|
|
170
|
+
const HALF_TICK_RANGE = 495n;
|
|
171
|
+
/** Tick domain supported by Morpho V2. */
|
|
172
|
+
const TICK_RANGE = 990;
|
|
173
|
+
/** Max allowed price (1e18 in wad). */
|
|
174
|
+
const MAX_PRICE = WAD$1;
|
|
175
|
+
/**
|
|
176
|
+
* Converts a tick to a wad price using the same approximation and rounding as TickLib.
|
|
177
|
+
* @param tick - Tick value in the inclusive range [0, 990].
|
|
178
|
+
* @returns The price in wad units.
|
|
179
|
+
* @throws {@link InvalidTickError} If tick is not an integer in range [0, 990].
|
|
180
|
+
*/
|
|
181
|
+
function tickToPrice(tick) {
|
|
182
|
+
assertTick(tick);
|
|
183
|
+
return divHalfDownUnchecked(divHalfDownUnchecked(WAD_SQUARED, WAD$1 + wExp(LN_ONE_PLUS_DELTA * (HALF_TICK_RANGE - BigInt(tick)))), PRICE_STEP) * PRICE_STEP;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Returns the lowest tick with a higher-or-equal price.
|
|
187
|
+
* @param price - Price in wad units.
|
|
188
|
+
* @returns The first tick whose {@link tickToPrice} is greater than or equal to `price`.
|
|
189
|
+
* @throws {@link InvalidPriceError} If price is outside [0, 1e18].
|
|
190
|
+
*/
|
|
191
|
+
function priceToTick(price) {
|
|
192
|
+
assertPrice(price);
|
|
193
|
+
let low = 0;
|
|
194
|
+
let high = TICK_RANGE;
|
|
195
|
+
while (low !== high) {
|
|
196
|
+
const mid = Math.floor((low + high) / 2);
|
|
197
|
+
if (tickToPrice(mid) < price) low = mid + 1;
|
|
198
|
+
else high = mid;
|
|
199
|
+
}
|
|
200
|
+
return low;
|
|
201
|
+
}
|
|
202
|
+
function divHalfDownUnchecked(x, d) {
|
|
203
|
+
return (x + (d - 1n) / 2n) / d;
|
|
204
|
+
}
|
|
205
|
+
function wExp(x) {
|
|
206
|
+
if (x < 0n) return WAD_SQUARED / wExp(-x);
|
|
207
|
+
const q = (x + LN2 / 2n) / LN2;
|
|
208
|
+
const r = x - q * LN2;
|
|
209
|
+
const secondTerm = r * r / (2n * WAD$1);
|
|
210
|
+
const thirdTerm = secondTerm * r / (3n * WAD$1);
|
|
211
|
+
return WAD$1 + r + secondTerm + thirdTerm << q;
|
|
212
|
+
}
|
|
213
|
+
function assertTick(tick) {
|
|
214
|
+
if (!Number.isInteger(tick) || tick < 0 || tick > TICK_RANGE) throw new InvalidTickError(tick);
|
|
215
|
+
}
|
|
216
|
+
function assertPrice(price) {
|
|
217
|
+
if (price < 0n || price > MAX_PRICE) throw new InvalidPriceError(price);
|
|
218
|
+
}
|
|
219
|
+
var InvalidTickError = class extends BaseError {
|
|
220
|
+
constructor(tick) {
|
|
221
|
+
super(`Invalid tick: ${tick}. Tick must be an integer between 0 and ${TICK_RANGE}.`);
|
|
222
|
+
_defineProperty(this, "name", "Tick.InvalidTickError");
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
var InvalidPriceError = class extends BaseError {
|
|
226
|
+
constructor(price) {
|
|
227
|
+
super(`Invalid price: ${price}. Price must be between 0 and ${MAX_PRICE}.`);
|
|
228
|
+
_defineProperty(this, "name", "Tick.InvalidPriceError");
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
|
|
232
|
+
//#endregion
|
|
55
233
|
//#region src/api/Schema/BookResponse.ts
|
|
56
234
|
var BookResponse_exports = /* @__PURE__ */ __exportAll({ from: () => from$15 });
|
|
57
235
|
function from$15(level) {
|
|
236
|
+
const price = tickToPrice(level.tick);
|
|
58
237
|
return {
|
|
59
|
-
|
|
238
|
+
tick: level.tick,
|
|
239
|
+
price: price.toString(),
|
|
60
240
|
assets: level.assets.toString(),
|
|
61
241
|
count: level.count
|
|
62
242
|
};
|
|
@@ -139,6 +319,61 @@ const MetaMorpho = (0, viem.parseAbi)([
|
|
|
139
319
|
//#region src/core/Abi/MetaMorphoFactory.ts
|
|
140
320
|
const MetaMorphoFactory = (0, viem.parseAbi)(["event CreateMetaMorpho(address indexed metaMorpho,address indexed caller,address initialOwner,uint256 initialTimelock,address indexed asset,string name,string symbol,bytes32 salt)", "function isMetaMorpho(address) view returns (bool)"]);
|
|
141
321
|
|
|
322
|
+
//#endregion
|
|
323
|
+
//#region src/core/Abi/MorphoV2.ts
|
|
324
|
+
const MorphoV2 = (0, viem.parseAbi)([
|
|
325
|
+
"constructor()",
|
|
326
|
+
"function collateralOf(bytes32 id, address user, address collateralToken) view returns (uint256)",
|
|
327
|
+
"function consume(bytes32 group, uint256 amount)",
|
|
328
|
+
"function consumed(address user, bytes32 group) view returns (uint256)",
|
|
329
|
+
"function debtOf(bytes32 id, address user) view returns (uint256)",
|
|
330
|
+
"function defaultFees(address loanToken, uint256 index) view returns (uint16)",
|
|
331
|
+
"function feeSetter() view returns (address)",
|
|
332
|
+
"function fees(bytes32 id) view returns (uint16[6])",
|
|
333
|
+
"function flashLoan(address token, uint256 assets, address callback, bytes data)",
|
|
334
|
+
"function isHealthy((address loanToken, (address token, uint256 lltv, address oracle)[] collaterals, uint256 maturity) obligation, bytes32 id, address borrower) view returns (bool)",
|
|
335
|
+
"function liquidate((address loanToken, (address token, uint256 lltv, address oracle)[] collaterals, uint256 maturity) obligation, (uint256 collateralIndex, uint256 repaid, uint256 seized)[] seizures, address borrower, bytes data) returns ((uint256 collateralIndex, uint256 repaid, uint256 seized)[])",
|
|
336
|
+
"function multicall(bytes[] calls)",
|
|
337
|
+
"function obligationCreated(bytes32 id) view returns (bool)",
|
|
338
|
+
"function obligationState(bytes32 id) view returns (uint128 totalUnits, uint128 totalShares, uint256 withdrawable, bool created)",
|
|
339
|
+
"function owner() view returns (address)",
|
|
340
|
+
"function repay((address loanToken, (address token, uint256 lltv, address oracle)[] collaterals, uint256 maturity) obligation, uint256 obligationUnits, address onBehalf)",
|
|
341
|
+
"function session(address user) view returns (bytes32)",
|
|
342
|
+
"function setDefaultTradingFee(address loanToken, uint256 index, uint256 newTradingFee)",
|
|
343
|
+
"function setFeeSetter(address newFeeSetter)",
|
|
344
|
+
"function setObligationTradingFee(bytes32 id, uint256 index, uint256 newTradingFee)",
|
|
345
|
+
"function setOwner(address newOwner)",
|
|
346
|
+
"function setTradingFeeRecipient(address recipient)",
|
|
347
|
+
"function sharesOf(bytes32 id, address user) view returns (uint256)",
|
|
348
|
+
"function shuffleSession()",
|
|
349
|
+
"function supplyCollateral((address loanToken, (address token, uint256 lltv, address oracle)[] collaterals, uint256 maturity) obligation, address collateral, uint256 assets, address onBehalf)",
|
|
350
|
+
"function take(uint256 buyerAssets, uint256 sellerAssets, uint256 obligationUnits, uint256 obligationShares, address taker, ((address loanToken, (address token, uint256 lltv, address oracle)[] collaterals, uint256 maturity) obligation, bool buy, address maker, uint256 assets, uint256 obligationUnits, uint256 obligationShares, uint256 start, uint256 expiry, uint256 tick, bytes32 group, bytes32 session, address callback, bytes callbackData) offer, (uint8 v, bytes32 r, bytes32 s) sig, bytes32 root, bytes32[] proof, address takerCallback, bytes takerCallbackData) returns (uint256, uint256, uint256, uint256)",
|
|
351
|
+
"function totalShares(bytes32 id) view returns (uint256)",
|
|
352
|
+
"function totalUnits(bytes32 id) view returns (uint256)",
|
|
353
|
+
"function touchObligation((address loanToken, (address token, uint256 lltv, address oracle)[] collaterals, uint256 maturity) obligation) returns (bytes32)",
|
|
354
|
+
"function tradingFee(bytes32 id, uint256 timeToMaturity) view returns (uint256)",
|
|
355
|
+
"function tradingFeeRecipient() view returns (address)",
|
|
356
|
+
"function withdraw((address loanToken, (address token, uint256 lltv, address oracle)[] collaterals, uint256 maturity) obligation, uint256 obligationUnits, uint256 shares, address onBehalf) returns (uint256, uint256)",
|
|
357
|
+
"function withdrawCollateral((address loanToken, (address token, uint256 lltv, address oracle)[] collaterals, uint256 maturity) obligation, address collateral, uint256 assets, address onBehalf)",
|
|
358
|
+
"function withdrawable(bytes32 id) view returns (uint256)",
|
|
359
|
+
"event Constructor(address indexed owner)",
|
|
360
|
+
"event Consume(address indexed user, bytes32 indexed group, uint256 amount)",
|
|
361
|
+
"event FlashLoan(address indexed caller, address indexed token, uint256 assets)",
|
|
362
|
+
"event Liquidate(address indexed caller, bytes32 indexed id, (uint256 collateralIndex, uint256 repaid, uint256 seized)[] seizures, address indexed borrower, uint256 totalRepaid, uint256 badDebt)",
|
|
363
|
+
"event ObligationCreated(bytes32 indexed id, (address loanToken, (address token, uint256 lltv, address oracle)[] collaterals, uint256 maturity) obligation)",
|
|
364
|
+
"event Repay(address indexed caller, bytes32 indexed id, uint256 obligationUnits, address indexed onBehalf)",
|
|
365
|
+
"event SetDefaultTradingFee(address indexed loanToken, uint256 indexed index, uint256 newTradingFee)",
|
|
366
|
+
"event SetFeeSetter(address indexed feeSetter)",
|
|
367
|
+
"event SetObligationTradingFee(bytes32 indexed id, uint256 indexed index, uint256 newTradingFee)",
|
|
368
|
+
"event SetOwner(address indexed owner)",
|
|
369
|
+
"event SetTradingFeeRecipient(address indexed recipient)",
|
|
370
|
+
"event ShuffleSession(address indexed user, bytes32 session)",
|
|
371
|
+
"event SupplyCollateral(address caller, bytes32 indexed id, address indexed collateral, uint256 assets, address indexed onBehalf)",
|
|
372
|
+
"event Take(address caller, bytes32 indexed id, address indexed maker, address indexed taker, bool offerIsBuy, uint256 buyerAssets, uint256 sellerAssets, uint256 obligationUnits, uint256 obligationShares, bool buyerIsLender, bool sellerIsBorrower, bytes32 group, uint256 consumed)",
|
|
373
|
+
"event Withdraw(address indexed caller, bytes32 indexed id, uint256 obligationUnits, uint256 shares, address indexed onBehalf)",
|
|
374
|
+
"event WithdrawCollateral(address caller, bytes32 indexed id, address indexed collateral, uint256 assets, address indexed onBehalf)"
|
|
375
|
+
]);
|
|
376
|
+
|
|
142
377
|
//#endregion
|
|
143
378
|
//#region src/core/Abi/index.ts
|
|
144
379
|
var Abi_exports = /* @__PURE__ */ __exportAll({
|
|
@@ -146,6 +381,7 @@ var Abi_exports = /* @__PURE__ */ __exportAll({
|
|
|
146
381
|
MetaMorpho: () => MetaMorpho,
|
|
147
382
|
MetaMorphoFactory: () => MetaMorphoFactory,
|
|
148
383
|
Morpho: () => Morpho,
|
|
384
|
+
MorphoV2: () => MorphoV2,
|
|
149
385
|
Oracle: () => Oracle
|
|
150
386
|
});
|
|
151
387
|
const Oracle = [{
|
|
@@ -348,105 +584,6 @@ function* batch$1(array, batchSize) {
|
|
|
348
584
|
for (let i = 0; i < array.length; i += batchSize) yield array.slice(i, i + batchSize);
|
|
349
585
|
}
|
|
350
586
|
|
|
351
|
-
//#endregion
|
|
352
|
-
//#region \0@oxc-project+runtime@0.110.0/helpers/typeof.js
|
|
353
|
-
function _typeof(o) {
|
|
354
|
-
"@babel/helpers - typeof";
|
|
355
|
-
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
356
|
-
return typeof o;
|
|
357
|
-
} : function(o) {
|
|
358
|
-
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
359
|
-
}, _typeof(o);
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
//#endregion
|
|
363
|
-
//#region \0@oxc-project+runtime@0.110.0/helpers/toPrimitive.js
|
|
364
|
-
function toPrimitive(t, r) {
|
|
365
|
-
if ("object" != _typeof(t) || !t) return t;
|
|
366
|
-
var e = t[Symbol.toPrimitive];
|
|
367
|
-
if (void 0 !== e) {
|
|
368
|
-
var i = e.call(t, r || "default");
|
|
369
|
-
if ("object" != _typeof(i)) return i;
|
|
370
|
-
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
371
|
-
}
|
|
372
|
-
return ("string" === r ? String : Number)(t);
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
//#endregion
|
|
376
|
-
//#region \0@oxc-project+runtime@0.110.0/helpers/toPropertyKey.js
|
|
377
|
-
function toPropertyKey(t) {
|
|
378
|
-
var i = toPrimitive(t, "string");
|
|
379
|
-
return "symbol" == _typeof(i) ? i : i + "";
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
//#endregion
|
|
383
|
-
//#region \0@oxc-project+runtime@0.110.0/helpers/defineProperty.js
|
|
384
|
-
function _defineProperty(e, r, t) {
|
|
385
|
-
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
386
|
-
value: t,
|
|
387
|
-
enumerable: !0,
|
|
388
|
-
configurable: !0,
|
|
389
|
-
writable: !0
|
|
390
|
-
}) : e[r] = t, e;
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
//#endregion
|
|
394
|
-
//#region src/utils/Errors.ts
|
|
395
|
-
var Errors_exports = /* @__PURE__ */ __exportAll({
|
|
396
|
-
BaseError: () => BaseError,
|
|
397
|
-
ReorgError: () => ReorgError
|
|
398
|
-
});
|
|
399
|
-
/**
|
|
400
|
-
* Base error class inherited by all errors thrown by mempool.
|
|
401
|
-
*
|
|
402
|
-
* @example
|
|
403
|
-
* ```ts
|
|
404
|
-
* import { Errors } from 'mempool'
|
|
405
|
-
* throw new Errors.BaseError('An error occurred')
|
|
406
|
-
* ```
|
|
407
|
-
*/
|
|
408
|
-
var BaseError = class BaseError extends Error {
|
|
409
|
-
constructor(shortMessage, options = {}) {
|
|
410
|
-
const details = (() => {
|
|
411
|
-
if (options.cause instanceof BaseError) {
|
|
412
|
-
if (options.cause.details) return options.cause.details;
|
|
413
|
-
if (options.cause.shortMessage) return options.cause.shortMessage;
|
|
414
|
-
}
|
|
415
|
-
if (options.cause && "details" in options.cause && typeof options.cause.details === "string") return options.cause.details;
|
|
416
|
-
if (options.cause?.message) return options.cause.message;
|
|
417
|
-
return options.details;
|
|
418
|
-
})();
|
|
419
|
-
const message = [
|
|
420
|
-
shortMessage || "An error occurred.",
|
|
421
|
-
...options.metaMessages ? ["", ...options.metaMessages] : [],
|
|
422
|
-
...details ? ["", details ? `Details: ${details}` : void 0] : []
|
|
423
|
-
].filter((x) => typeof x === "string").join("\n");
|
|
424
|
-
super(message, options.cause ? { cause: options.cause } : void 0);
|
|
425
|
-
_defineProperty(this, "details", void 0);
|
|
426
|
-
_defineProperty(this, "shortMessage", void 0);
|
|
427
|
-
_defineProperty(this, "cause", void 0);
|
|
428
|
-
_defineProperty(this, "name", "BaseError");
|
|
429
|
-
this.cause = options.cause;
|
|
430
|
-
this.details = details;
|
|
431
|
-
this.shortMessage = shortMessage;
|
|
432
|
-
}
|
|
433
|
-
walk(fn) {
|
|
434
|
-
return walk(this, fn);
|
|
435
|
-
}
|
|
436
|
-
};
|
|
437
|
-
/** @internal */
|
|
438
|
-
function walk(err, fn) {
|
|
439
|
-
if (fn?.(err)) return err;
|
|
440
|
-
if (err && typeof err === "object" && "cause" in err && err.cause) return walk(err.cause, fn);
|
|
441
|
-
return fn ? null : err;
|
|
442
|
-
}
|
|
443
|
-
var ReorgError = class extends BaseError {
|
|
444
|
-
constructor(blockNumber) {
|
|
445
|
-
super(`Reorg detected at block number ${blockNumber}`);
|
|
446
|
-
_defineProperty(this, "name", "ReorgError");
|
|
447
|
-
}
|
|
448
|
-
};
|
|
449
|
-
|
|
450
587
|
//#endregion
|
|
451
588
|
//#region src/core/Chain.ts
|
|
452
589
|
var Chain_exports = /* @__PURE__ */ __exportAll({
|
|
@@ -551,8 +688,8 @@ const chains$1 = {
|
|
|
551
688
|
name: "ethereum-virtual-testnet",
|
|
552
689
|
custom: {
|
|
553
690
|
morpho: {
|
|
554
|
-
address: "
|
|
555
|
-
blockCreated:
|
|
691
|
+
address: "0x634b095371e4e45feed94c1a45c37798e173ea50",
|
|
692
|
+
blockCreated: 23226700
|
|
556
693
|
},
|
|
557
694
|
morphoBlue: {
|
|
558
695
|
address: "0xBBBBBbbBBb9cC5e90e3b3Af64bdAF62C37EEFFCb",
|
|
@@ -1493,7 +1630,7 @@ const OfferSchema = () => {
|
|
|
1493
1630
|
assets: zod.bigint({ coerce: true }).min(0n).max(viem.maxUint256),
|
|
1494
1631
|
obligationUnits: zod.bigint({ coerce: true }).min(0n).max(viem.maxUint256).optional().default(0n),
|
|
1495
1632
|
obligationShares: zod.bigint({ coerce: true }).min(0n).max(viem.maxUint256).optional().default(0n),
|
|
1496
|
-
|
|
1633
|
+
tick: zod.coerce.number().int().min(0).max(990),
|
|
1497
1634
|
maturity: MaturitySchema,
|
|
1498
1635
|
expiry: zod.number().int().max(Number.MAX_SAFE_INTEGER),
|
|
1499
1636
|
start: zod.number().int().max(Number.MAX_SAFE_INTEGER),
|
|
@@ -1565,7 +1702,7 @@ const serialize = (offer) => ({
|
|
|
1565
1702
|
assets: offer.assets.toString(),
|
|
1566
1703
|
obligationUnits: offer.obligationUnits.toString(),
|
|
1567
1704
|
obligationShares: offer.obligationShares.toString(),
|
|
1568
|
-
|
|
1705
|
+
tick: offer.tick,
|
|
1569
1706
|
maturity: Number(offer.maturity),
|
|
1570
1707
|
expiry: Number(offer.expiry),
|
|
1571
1708
|
start: Number(offer.start),
|
|
@@ -1610,14 +1747,13 @@ function random$1(config) {
|
|
|
1610
1747
|
[.98, 2]
|
|
1611
1748
|
]));
|
|
1612
1749
|
const buy = config?.buy !== void 0 ? config.buy : bool();
|
|
1613
|
-
const
|
|
1614
|
-
const
|
|
1615
|
-
const
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
return [BigInt(q) * (ONE / 4n), buy ? 1 + idx : 1 + (len - 1 - idx)];
|
|
1750
|
+
const tickMin = buy ? 0 : 495;
|
|
1751
|
+
const len = (buy ? 495 : 990) - tickMin + 1;
|
|
1752
|
+
const tickPairs = Array.from({ length: len }, (_, idx) => {
|
|
1753
|
+
const weight = buy ? 1 + idx : 1 + (len - 1 - idx);
|
|
1754
|
+
return [tickMin + idx, weight];
|
|
1619
1755
|
});
|
|
1620
|
-
const
|
|
1756
|
+
const tick = config?.tick ?? weightedChoice(tickPairs);
|
|
1621
1757
|
const loanTokenDecimals = config?.assetsDecimals?.[loanToken] ?? 18;
|
|
1622
1758
|
const unit = BigInt(10) ** BigInt(loanTokenDecimals);
|
|
1623
1759
|
const amountBase = BigInt(100 + int(999901));
|
|
@@ -1631,7 +1767,7 @@ function random$1(config) {
|
|
|
1631
1767
|
assets: assetsScaled,
|
|
1632
1768
|
obligationUnits: config?.obligationUnits ?? 0n,
|
|
1633
1769
|
obligationShares: config?.obligationShares ?? 0n,
|
|
1634
|
-
|
|
1770
|
+
tick,
|
|
1635
1771
|
maturity,
|
|
1636
1772
|
expiry: config?.expiry ?? maturity - 1,
|
|
1637
1773
|
start: config?.start ?? maturity - 10,
|
|
@@ -1696,7 +1832,7 @@ const types = {
|
|
|
1696
1832
|
type: "uint256"
|
|
1697
1833
|
},
|
|
1698
1834
|
{
|
|
1699
|
-
name: "
|
|
1835
|
+
name: "tick",
|
|
1700
1836
|
type: "uint256"
|
|
1701
1837
|
},
|
|
1702
1838
|
{
|
|
@@ -1764,7 +1900,7 @@ function hash(offer) {
|
|
|
1764
1900
|
assets: offer.assets,
|
|
1765
1901
|
obligationUnits: offer.obligationUnits,
|
|
1766
1902
|
obligationShares: offer.obligationShares,
|
|
1767
|
-
|
|
1903
|
+
tick: BigInt(offer.tick),
|
|
1768
1904
|
maturity: BigInt(offer.maturity),
|
|
1769
1905
|
expiry: BigInt(offer.expiry),
|
|
1770
1906
|
group: offer.group,
|
|
@@ -1815,7 +1951,7 @@ const OfferAbi = [
|
|
|
1815
1951
|
type: "uint256"
|
|
1816
1952
|
},
|
|
1817
1953
|
{
|
|
1818
|
-
name: "
|
|
1954
|
+
name: "tick",
|
|
1819
1955
|
type: "uint256"
|
|
1820
1956
|
},
|
|
1821
1957
|
{
|
|
@@ -1886,7 +2022,7 @@ function encode$1(offer) {
|
|
|
1886
2022
|
offer.assets,
|
|
1887
2023
|
offer.obligationUnits,
|
|
1888
2024
|
offer.obligationShares,
|
|
1889
|
-
offer.
|
|
2025
|
+
BigInt(offer.tick),
|
|
1890
2026
|
BigInt(offer.maturity),
|
|
1891
2027
|
BigInt(offer.expiry),
|
|
1892
2028
|
offer.group,
|
|
@@ -1911,7 +2047,7 @@ function decode$1(data) {
|
|
|
1911
2047
|
assets: decoded[1],
|
|
1912
2048
|
obligationUnits: decoded[2],
|
|
1913
2049
|
obligationShares: decoded[3],
|
|
1914
|
-
|
|
2050
|
+
tick: Number(decoded[4]),
|
|
1915
2051
|
maturity: from$11(Number(decoded[5])),
|
|
1916
2052
|
expiry: Number(decoded[6]),
|
|
1917
2053
|
group: decoded[7],
|
|
@@ -2775,6 +2911,16 @@ const BrandTypeId = Symbol.for("mempool/Brand");
|
|
|
2775
2911
|
//#endregion
|
|
2776
2912
|
//#region src/api/Schema/OfferResponse.ts
|
|
2777
2913
|
var OfferResponse_exports = /* @__PURE__ */ __exportAll({ from: () => from$2 });
|
|
2914
|
+
function normalizeChainId(chainId) {
|
|
2915
|
+
const parsedChainId = Number(chainId);
|
|
2916
|
+
if (!Number.isInteger(parsedChainId) || parsedChainId <= 0) throw new Error(`Invalid chain id: ${String(chainId)}`);
|
|
2917
|
+
return parsedChainId;
|
|
2918
|
+
}
|
|
2919
|
+
function normalizeBlockNumber(blockNumber) {
|
|
2920
|
+
const parsedBlockNumber = Number(blockNumber);
|
|
2921
|
+
if (!Number.isInteger(parsedBlockNumber) || parsedBlockNumber < 0) throw new Error(`Invalid block number: ${String(blockNumber)}`);
|
|
2922
|
+
return parsedBlockNumber;
|
|
2923
|
+
}
|
|
2778
2924
|
/**
|
|
2779
2925
|
* Creates an `OfferResponse` matching the Solidity Offer struct layout.
|
|
2780
2926
|
* @constructor
|
|
@@ -2782,6 +2928,8 @@ var OfferResponse_exports = /* @__PURE__ */ __exportAll({ from: () => from$2 });
|
|
|
2782
2928
|
* @returns The created `OfferResponse`. {@link OfferResponse}
|
|
2783
2929
|
*/
|
|
2784
2930
|
function from$2(input) {
|
|
2931
|
+
const chainId = normalizeChainId(input.chainId);
|
|
2932
|
+
const blockNumber = normalizeBlockNumber(input.blockNumber);
|
|
2785
2933
|
const base = {
|
|
2786
2934
|
offer: {
|
|
2787
2935
|
obligation: {
|
|
@@ -2800,7 +2948,7 @@ function from$2(input) {
|
|
|
2800
2948
|
obligation_shares: input.obligationShares.toString(),
|
|
2801
2949
|
start: input.start,
|
|
2802
2950
|
expiry: input.expiry,
|
|
2803
|
-
|
|
2951
|
+
tick: input.tick,
|
|
2804
2952
|
group: input.group,
|
|
2805
2953
|
session: input.session,
|
|
2806
2954
|
callback: input.callback.address,
|
|
@@ -2808,15 +2956,15 @@ function from$2(input) {
|
|
|
2808
2956
|
},
|
|
2809
2957
|
offer_hash: input.hash,
|
|
2810
2958
|
obligation_id: id({
|
|
2811
|
-
chainId
|
|
2959
|
+
chainId,
|
|
2812
2960
|
loanToken: input.loanToken,
|
|
2813
2961
|
collaterals: [...input.collaterals],
|
|
2814
2962
|
maturity: input.maturity
|
|
2815
2963
|
}),
|
|
2816
|
-
chain_id:
|
|
2964
|
+
chain_id: chainId,
|
|
2817
2965
|
consumed: input.consumed.toString(),
|
|
2818
2966
|
takeable: input.takeable.toString(),
|
|
2819
|
-
block_number:
|
|
2967
|
+
block_number: blockNumber
|
|
2820
2968
|
};
|
|
2821
2969
|
if (!input.proof || !input.root || !input.signature) return {
|
|
2822
2970
|
...base,
|
|
@@ -2873,7 +3021,7 @@ const offerExample = {
|
|
|
2873
3021
|
obligation_shares: "0",
|
|
2874
3022
|
start: 1761922790,
|
|
2875
3023
|
expiry: 1761922799,
|
|
2876
|
-
|
|
3024
|
+
tick: 495,
|
|
2877
3025
|
group: "0x000000000000000000000000000000000000000000000000000000000008b8f4",
|
|
2878
3026
|
session: "0x0000000000000000000000000000000000000000000000000000000000000000",
|
|
2879
3027
|
callback: "0x0000000000000000000000000000000000000000",
|
|
@@ -2914,7 +3062,7 @@ const validateOfferExample = {
|
|
|
2914
3062
|
assets: "369216000000000000000000",
|
|
2915
3063
|
obligation_units: "0",
|
|
2916
3064
|
obligation_shares: "0",
|
|
2917
|
-
|
|
3065
|
+
tick: 495,
|
|
2918
3066
|
maturity: 1761922799,
|
|
2919
3067
|
expiry: 1761922799,
|
|
2920
3068
|
start: 1761922790,
|
|
@@ -3058,9 +3206,11 @@ __decorate([(0, openapi_metadata_decorators.ApiProperty)({
|
|
|
3058
3206
|
example: offerExample.offer.expiry
|
|
3059
3207
|
})], OfferDataResponse.prototype, "expiry", void 0);
|
|
3060
3208
|
__decorate([(0, openapi_metadata_decorators.ApiProperty)({
|
|
3061
|
-
type: "
|
|
3062
|
-
example: offerExample.offer.
|
|
3063
|
-
|
|
3209
|
+
type: "number",
|
|
3210
|
+
example: offerExample.offer.tick,
|
|
3211
|
+
minimum: 0,
|
|
3212
|
+
maximum: 990
|
|
3213
|
+
})], OfferDataResponse.prototype, "tick", void 0);
|
|
3064
3214
|
__decorate([(0, openapi_metadata_decorators.ApiProperty)({
|
|
3065
3215
|
type: "string",
|
|
3066
3216
|
example: offerExample.offer.group
|
|
@@ -3301,9 +3451,11 @@ __decorate([(0, openapi_metadata_decorators.ApiProperty)({
|
|
|
3301
3451
|
required: false
|
|
3302
3452
|
})], ValidateOfferRequest.prototype, "obligation_shares", void 0);
|
|
3303
3453
|
__decorate([(0, openapi_metadata_decorators.ApiProperty)({
|
|
3304
|
-
type: "
|
|
3305
|
-
example: validateOfferExample.
|
|
3306
|
-
|
|
3454
|
+
type: "number",
|
|
3455
|
+
example: validateOfferExample.tick,
|
|
3456
|
+
minimum: 0,
|
|
3457
|
+
maximum: 990
|
|
3458
|
+
})], ValidateOfferRequest.prototype, "tick", void 0);
|
|
3307
3459
|
__decorate([(0, openapi_metadata_decorators.ApiProperty)({
|
|
3308
3460
|
type: "number",
|
|
3309
3461
|
example: validateOfferExample.maturity
|
|
@@ -3403,9 +3555,16 @@ __decorate([(0, openapi_metadata_decorators.ApiProperty)({
|
|
|
3403
3555
|
description: "List of validation issues. Returned when any offer fails validation."
|
|
3404
3556
|
})], ValidationFailureResponse.prototype, "data", void 0);
|
|
3405
3557
|
var BookLevelResponse = class {};
|
|
3558
|
+
__decorate([(0, openapi_metadata_decorators.ApiProperty)({
|
|
3559
|
+
type: "number",
|
|
3560
|
+
example: 495,
|
|
3561
|
+
minimum: 0,
|
|
3562
|
+
maximum: 990
|
|
3563
|
+
})], BookLevelResponse.prototype, "tick", void 0);
|
|
3406
3564
|
__decorate([(0, openapi_metadata_decorators.ApiProperty)({
|
|
3407
3565
|
type: "string",
|
|
3408
|
-
example: "
|
|
3566
|
+
example: "500000000000000000",
|
|
3567
|
+
description: "Price derived from tick, scaled by 1e18."
|
|
3409
3568
|
})], BookLevelResponse.prototype, "price", void 0);
|
|
3410
3569
|
__decorate([(0, openapi_metadata_decorators.ApiProperty)({
|
|
3411
3570
|
type: "string",
|
|
@@ -3419,6 +3578,7 @@ const positionExample = {
|
|
|
3419
3578
|
chain_id: 1,
|
|
3420
3579
|
contract: "0xC9A9C45C0eB717f8b5F193Af6bAa05A1c0Ac5078",
|
|
3421
3580
|
user: "0x7b093658BE7f90B63D7c359e8f408e503c2D9401",
|
|
3581
|
+
obligation_id: "0x12590ae1aee324a005be565f3bcdd16dbf8daf7969b26c181c8b8f467dad9f67",
|
|
3422
3582
|
reserved: "200000000000000000000",
|
|
3423
3583
|
block_number: 21345678
|
|
3424
3584
|
};
|
|
@@ -3435,6 +3595,12 @@ __decorate([(0, openapi_metadata_decorators.ApiProperty)({
|
|
|
3435
3595
|
type: "string",
|
|
3436
3596
|
example: positionExample.user
|
|
3437
3597
|
})], PositionListItemResponse.prototype, "user", void 0);
|
|
3598
|
+
__decorate([(0, openapi_metadata_decorators.ApiProperty)({
|
|
3599
|
+
type: "string",
|
|
3600
|
+
nullable: true,
|
|
3601
|
+
example: positionExample.obligation_id,
|
|
3602
|
+
description: "Obligation id this reserved amount belongs to, or null if no lots exist."
|
|
3603
|
+
})], PositionListItemResponse.prototype, "obligation_id", void 0);
|
|
3438
3604
|
__decorate([(0, openapi_metadata_decorators.ApiProperty)({
|
|
3439
3605
|
type: "string",
|
|
3440
3606
|
example: positionExample.reserved
|
|
@@ -3462,7 +3628,7 @@ __decorate([(0, openapi_metadata_decorators.ApiProperty)({
|
|
|
3462
3628
|
})], BookListResponse.prototype, "cursor", void 0);
|
|
3463
3629
|
__decorate([(0, openapi_metadata_decorators.ApiProperty)({
|
|
3464
3630
|
type: () => [BookLevelResponse],
|
|
3465
|
-
description: "Aggregated book levels grouped by
|
|
3631
|
+
description: "Aggregated book levels grouped by offer tick."
|
|
3466
3632
|
})], BookListResponse.prototype, "data", void 0);
|
|
3467
3633
|
let BooksController = class BooksController {
|
|
3468
3634
|
async getBook() {}
|
|
@@ -3472,7 +3638,7 @@ __decorate([
|
|
|
3472
3638
|
methods: ["get"],
|
|
3473
3639
|
path: "/v1/books/{obligationId}/{side}",
|
|
3474
3640
|
summary: "Get aggregated book",
|
|
3475
|
-
description: "Returns aggregated book data for a given obligation and side. Offers are grouped by
|
|
3641
|
+
description: "Returns aggregated book data for a given obligation and side. Offers are grouped by tick with summed takeable amounts, and each level includes the corresponding wad-scaled price. Book levels are sorted by tick (ascending for sell side, descending for buy side)."
|
|
3476
3642
|
}),
|
|
3477
3643
|
(0, openapi_metadata_decorators.ApiParam)({
|
|
3478
3644
|
name: "obligationId",
|
|
@@ -3497,7 +3663,7 @@ __decorate([
|
|
|
3497
3663
|
name: "limit",
|
|
3498
3664
|
type: "number",
|
|
3499
3665
|
example: 10,
|
|
3500
|
-
description: "Maximum number of
|
|
3666
|
+
description: "Maximum number of tick levels to return."
|
|
3501
3667
|
}),
|
|
3502
3668
|
(0, openapi_metadata_decorators.ApiResponse)({
|
|
3503
3669
|
status: 200,
|
|
@@ -3691,6 +3857,11 @@ const configRulesLoanTokenExample = {
|
|
|
3691
3857
|
chain_id: 1,
|
|
3692
3858
|
address: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"
|
|
3693
3859
|
};
|
|
3860
|
+
const configRulesCollateralTokenExample = {
|
|
3861
|
+
type: "collateral_token",
|
|
3862
|
+
chain_id: 1,
|
|
3863
|
+
address: "0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0"
|
|
3864
|
+
};
|
|
3694
3865
|
const configRulesOracleExample = {
|
|
3695
3866
|
type: "oracle",
|
|
3696
3867
|
chain_id: 1,
|
|
@@ -3700,6 +3871,7 @@ const configRulesChecksumExample = "f1d2d2f924e986ac86fdf7b36c94bcdf";
|
|
|
3700
3871
|
const configRulesPayloadExample = [
|
|
3701
3872
|
configRulesMaturityExample,
|
|
3702
3873
|
configRulesLoanTokenExample,
|
|
3874
|
+
configRulesCollateralTokenExample,
|
|
3703
3875
|
configRulesOracleExample
|
|
3704
3876
|
];
|
|
3705
3877
|
const configContractNames = [
|
|
@@ -3826,7 +3998,7 @@ __decorate([
|
|
|
3826
3998
|
methods: ["get"],
|
|
3827
3999
|
path: "/v1/config/rules",
|
|
3828
4000
|
summary: "Get config rules",
|
|
3829
|
-
description: "Returns configured rules (maturities, loan tokens, oracles) for supported chains."
|
|
4001
|
+
description: "Returns configured rules (maturities, loan tokens, collateral tokens, oracles) for supported chains."
|
|
3830
4002
|
}),
|
|
3831
4003
|
(0, openapi_metadata_decorators.ApiQuery)({
|
|
3832
4004
|
name: "cursor",
|
|
@@ -3846,7 +4018,7 @@ __decorate([
|
|
|
3846
4018
|
name: "types",
|
|
3847
4019
|
type: ["string"],
|
|
3848
4020
|
required: false,
|
|
3849
|
-
example: "maturity,loan_token,oracle",
|
|
4021
|
+
example: "maturity,loan_token,collateral_token,oracle",
|
|
3850
4022
|
description: "Filter by rule types (comma-separated).",
|
|
3851
4023
|
style: "form",
|
|
3852
4024
|
explode: false
|
|
@@ -3964,7 +4136,7 @@ __decorate([
|
|
|
3964
4136
|
methods: ["get"],
|
|
3965
4137
|
path: "/v1/users/{userAddress}/positions",
|
|
3966
4138
|
summary: "Get user positions",
|
|
3967
|
-
description: "Returns positions for a user with reserved balance.
|
|
4139
|
+
description: "Returns positions for a user with reserved balance per obligation. Each (position, obligation) pair is returned as a separate row. Positions with no lots return a single row with obligation_id = null and reserved = 0."
|
|
3968
4140
|
}),
|
|
3969
4141
|
(0, openapi_metadata_decorators.ApiParam)({
|
|
3970
4142
|
name: "userAddress",
|
|
@@ -4052,6 +4224,7 @@ function from$1(position) {
|
|
|
4052
4224
|
chain_id: position.chainId,
|
|
4053
4225
|
contract: position.contract,
|
|
4054
4226
|
user: position.user,
|
|
4227
|
+
obligation_id: position.obligationId,
|
|
4055
4228
|
reserved: position.reserved.toString(),
|
|
4056
4229
|
block_number: position.blockNumber
|
|
4057
4230
|
};
|
|
@@ -4105,10 +4278,11 @@ const ConfigRuleTypes = zod.enum([
|
|
|
4105
4278
|
"maturity",
|
|
4106
4279
|
"callback",
|
|
4107
4280
|
"loan_token",
|
|
4281
|
+
"collateral_token",
|
|
4108
4282
|
"oracle"
|
|
4109
4283
|
]);
|
|
4110
4284
|
const GetConfigRulesQueryParams = zod.object({
|
|
4111
|
-
cursor: zod.string().regex(/^(maturity|callback|loan_token|oracle):[1-9]\d*:.+$/, { message: "Cursor must be in the format type:chain_id:<value>" }).optional().meta({
|
|
4285
|
+
cursor: zod.string().regex(/^(maturity|callback|loan_token|collateral_token|oracle):[1-9]\d*:.+$/, { message: "Cursor must be in the format type:chain_id:<value>" }).optional().meta({
|
|
4112
4286
|
description: "Pagination cursor in type:chain_id:<value> format",
|
|
4113
4287
|
example: "maturity:1:1730415600:end_of_next_month"
|
|
4114
4288
|
}),
|
|
@@ -4118,7 +4292,7 @@ const GetConfigRulesQueryParams = zod.object({
|
|
|
4118
4292
|
}),
|
|
4119
4293
|
types: csvArray(ConfigRuleTypes).meta({
|
|
4120
4294
|
description: "Filter by rule types (comma-separated).",
|
|
4121
|
-
example: "maturity,loan_token,oracle"
|
|
4295
|
+
example: "maturity,loan_token,collateral_token,oracle"
|
|
4122
4296
|
}),
|
|
4123
4297
|
chains: csvArray(zod.string().regex(/^[1-9]\d*$/, { message: "Chain must be a positive integer" }).transform((val) => Number.parseInt(val, 10))).meta({
|
|
4124
4298
|
description: "Filter by chain IDs (comma-separated).",
|
|
@@ -4218,12 +4392,11 @@ const GetObligationParams = zod.object({ obligation_id: zod.string({ error: "Obl
|
|
|
4218
4392
|
description: "Obligation id",
|
|
4219
4393
|
example: "0x1234567890123456789012345678901234567890123456789012345678901234"
|
|
4220
4394
|
}) });
|
|
4221
|
-
/** Validate a book cursor format: {side,
|
|
4395
|
+
/** Validate a book cursor format: {side, lastTick, offersCursor} */
|
|
4222
4396
|
function isValidBookCursor(cursorString) {
|
|
4223
|
-
const isNumericString = (value) => typeof value === "string" && /^-?\d+$/.test(value);
|
|
4224
4397
|
try {
|
|
4225
4398
|
const v = JSON.parse(Buffer.from(cursorString, "base64url").toString("utf8"));
|
|
4226
|
-
return (v?.side === "buy" || v?.side === "sell") &&
|
|
4399
|
+
return (v?.side === "buy" || v?.side === "sell") && typeof v?.lastTick === "number" && Number.isInteger(v.lastTick) && (v?.offersCursor === null || typeof v?.offersCursor === "string");
|
|
4227
4400
|
} catch {
|
|
4228
4401
|
return false;
|
|
4229
4402
|
}
|
|
@@ -4384,7 +4557,7 @@ async function getOffers(apiClient, parameters) {
|
|
|
4384
4557
|
assets: offerData.assets,
|
|
4385
4558
|
obligation_units: offerData.obligation_units,
|
|
4386
4559
|
obligation_shares: offerData.obligation_shares,
|
|
4387
|
-
|
|
4560
|
+
tick: offerData.tick,
|
|
4388
4561
|
maturity: from$11(offerData.obligation.maturity),
|
|
4389
4562
|
expiry: offerData.expiry,
|
|
4390
4563
|
start: offerData.start,
|
|
@@ -4732,6 +4905,33 @@ const assets = {
|
|
|
4732
4905
|
"0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599"
|
|
4733
4906
|
]
|
|
4734
4907
|
};
|
|
4908
|
+
const collateralAssets = {
|
|
4909
|
+
[ChainId.ETHEREUM.toString()]: [
|
|
4910
|
+
"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
|
|
4911
|
+
"0x1aBaEA1f7C830bD89Acc67eC4af516284b1bC33c",
|
|
4912
|
+
"0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599",
|
|
4913
|
+
"0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0"
|
|
4914
|
+
],
|
|
4915
|
+
[ChainId.BASE.toString()]: [
|
|
4916
|
+
"0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
|
|
4917
|
+
"0x4200000000000000000000000000000000000006",
|
|
4918
|
+
"0xcbB7C0000aB88B473b1f5aFd9ef808440eed33Bf",
|
|
4919
|
+
"0xc1CBa3fCea344f92D9239c08C0568f6F2F0ee452",
|
|
4920
|
+
"0x60a3E35Cc302bFA44Cb288Bc5a4F316Fdb1adb42"
|
|
4921
|
+
],
|
|
4922
|
+
[ChainId["ETHEREUM-VIRTUAL-TESTNET"].toString()]: [
|
|
4923
|
+
"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
|
|
4924
|
+
"0x1aBaEA1f7C830bD89Acc67eC4af516284b1bC33c",
|
|
4925
|
+
"0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599",
|
|
4926
|
+
"0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0"
|
|
4927
|
+
],
|
|
4928
|
+
[ChainId.ANVIL.toString()]: [
|
|
4929
|
+
"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
|
|
4930
|
+
"0x1aBaEA1f7C830bD89Acc67eC4af516284b1bC33c",
|
|
4931
|
+
"0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599",
|
|
4932
|
+
"0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0"
|
|
4933
|
+
]
|
|
4934
|
+
};
|
|
4735
4935
|
const oracles = {
|
|
4736
4936
|
[ChainId.ETHEREUM.toString()]: [
|
|
4737
4937
|
"0xDddd770BADd886dF3864029e4B377B5F6a2B6b83",
|
|
@@ -4794,10 +4994,11 @@ var Rules_exports = /* @__PURE__ */ __exportAll({
|
|
|
4794
4994
|
amountMutualExclusivity: () => amountMutualExclusivity,
|
|
4795
4995
|
callback: () => callback,
|
|
4796
4996
|
chains: () => chains,
|
|
4997
|
+
collateralToken: () => collateralToken,
|
|
4998
|
+
loanToken: () => loanToken,
|
|
4797
4999
|
maturity: () => maturity,
|
|
4798
5000
|
oracle: () => oracle,
|
|
4799
5001
|
sameMaker: () => sameMaker,
|
|
4800
|
-
token: () => token,
|
|
4801
5002
|
validity: () => validity
|
|
4802
5003
|
});
|
|
4803
5004
|
/**
|
|
@@ -4825,15 +5026,25 @@ const callback = ({ callbacks }) => single("callback", `Validates callbacks: buy
|
|
|
4825
5026
|
if (isEmptyCallback(offer) && !offer.buy && !callbacks.includes(Type$1.SellWithEmptyCallback)) return { message: "Sell offers with empty callback not allowed." };
|
|
4826
5027
|
});
|
|
4827
5028
|
/**
|
|
4828
|
-
* A validation rule that checks if the offer's
|
|
4829
|
-
* @param assetsByChainId - Allowed
|
|
5029
|
+
* A validation rule that checks if the offer's loan token is allowed for its chain.
|
|
5030
|
+
* @param assetsByChainId - Allowed loan tokens indexed by chain id.
|
|
4830
5031
|
* @returns The issue that was found. If the offer is valid, this will be undefined.
|
|
4831
5032
|
*/
|
|
4832
|
-
const
|
|
4833
|
-
const
|
|
4834
|
-
if (!
|
|
4835
|
-
if (!
|
|
4836
|
-
|
|
5033
|
+
const loanToken = ({ assetsByChainId }) => single("loan_token", "Validates that offer loan token is in the allowed token list for the offer chain", (offer) => {
|
|
5034
|
+
const allowedLoanTokens = assetsByChainId[offer.chainId]?.map((asset) => asset.toLowerCase());
|
|
5035
|
+
if (!allowedLoanTokens || allowedLoanTokens.length === 0) return { message: `No allowed loan tokens for chain ${offer.chainId}` };
|
|
5036
|
+
if (!allowedLoanTokens.includes(offer.loanToken.toLowerCase())) return { message: "Loan token is not allowed" };
|
|
5037
|
+
});
|
|
5038
|
+
/**
|
|
5039
|
+
* A validation rule that checks if the offer's collateral tokens are allowed for its chain.
|
|
5040
|
+
* @param collateralAssetsByChainId - Allowed collateral tokens indexed by chain id.
|
|
5041
|
+
* @returns The issue that was found. If the offer is valid, this will be undefined.
|
|
5042
|
+
*/
|
|
5043
|
+
const collateralToken = ({ collateralAssetsByChainId }) => single("collateral_token", "Validates that offer collateral tokens are in the allowed token list for the offer chain", (offer) => {
|
|
5044
|
+
const allowedCollateralTokens = collateralAssetsByChainId[offer.chainId]?.map((asset) => asset.toLowerCase()) ?? [];
|
|
5045
|
+
if (allowedCollateralTokens.length === 0) return { message: `No allowed collateral tokens for chain ${offer.chainId}` };
|
|
5046
|
+
if (offer.collaterals.length === 0) return { message: "At least one collateral token is required" };
|
|
5047
|
+
if (offer.collaterals.some((collateral) => !allowedCollateralTokens.includes(collateral.asset.toLowerCase()))) return { message: "Collateral token is not allowed" };
|
|
4837
5048
|
});
|
|
4838
5049
|
/**
|
|
4839
5050
|
* A validation rule that checks if the offer's oracle addresses are allowed for its chain.
|
|
@@ -4876,9 +5087,11 @@ const amountMutualExclusivity = () => single("amount_mutual_exclusivity", "Valid
|
|
|
4876
5087
|
//#region src/gatekeeper/morphoRules.ts
|
|
4877
5088
|
const morphoRules = (chains$2) => {
|
|
4878
5089
|
const assetsByChainId = {};
|
|
5090
|
+
const collateralAssetsByChainId = {};
|
|
4879
5091
|
const oraclesByChainId = {};
|
|
4880
5092
|
for (const chain of chains$2) {
|
|
4881
5093
|
assetsByChainId[chain.id] = assets[chain.id.toString()] ?? [];
|
|
5094
|
+
collateralAssetsByChainId[chain.id] = collateralAssets[chain.id.toString()] ?? [];
|
|
4882
5095
|
oraclesByChainId[chain.id] = oracles[chain.id.toString()] ?? [];
|
|
4883
5096
|
}
|
|
4884
5097
|
return [
|
|
@@ -4890,7 +5103,8 @@ const morphoRules = (chains$2) => {
|
|
|
4890
5103
|
callbacks: [Type$1.BuyWithEmptyCallback, Type$1.SellWithEmptyCallback],
|
|
4891
5104
|
allowedAddresses: []
|
|
4892
5105
|
}),
|
|
4893
|
-
|
|
5106
|
+
loanToken({ assetsByChainId }),
|
|
5107
|
+
collateralToken({ collateralAssetsByChainId }),
|
|
4894
5108
|
oracle({ oraclesByChainId })
|
|
4895
5109
|
];
|
|
4896
5110
|
};
|
|
@@ -5349,6 +5563,12 @@ Object.defineProperty(exports, 'Rules', {
|
|
|
5349
5563
|
return Rules_exports;
|
|
5350
5564
|
}
|
|
5351
5565
|
});
|
|
5566
|
+
Object.defineProperty(exports, 'Tick', {
|
|
5567
|
+
enumerable: true,
|
|
5568
|
+
get: function () {
|
|
5569
|
+
return Tick_exports;
|
|
5570
|
+
}
|
|
5571
|
+
});
|
|
5352
5572
|
Object.defineProperty(exports, 'Time', {
|
|
5353
5573
|
enumerable: true,
|
|
5354
5574
|
get: function () {
|