@morpho-dev/router 0.0.18 → 0.0.19
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/index.browser.d.cts +19 -19
- package/dist/index.browser.d.ts +19 -19
- package/dist/index.browser.js +181 -108
- package/dist/index.browser.js.map +1 -1
- package/dist/index.browser.mjs +182 -109
- package/dist/index.browser.mjs.map +1 -1
- package/dist/index.node.d.cts +31 -31
- package/dist/index.node.d.ts +31 -31
- package/dist/index.node.js +181 -108
- package/dist/index.node.js.map +1 -1
- package/dist/index.node.mjs +183 -110
- package/dist/index.node.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.browser.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as _morpho_dev_mempool from '@morpho-dev/mempool';
|
|
2
|
-
import { Compute, Offer, Errors, Format } from '@morpho-dev/mempool';
|
|
2
|
+
import { Compute, Offer, Errors, Format, Maturity, LLTV } from '@morpho-dev/mempool';
|
|
3
3
|
export * from '@morpho-dev/mempool';
|
|
4
4
|
import * as viem from 'viem';
|
|
5
5
|
import { Address, Hex, PublicClient } from 'viem';
|
|
@@ -158,9 +158,9 @@ type GetParameters = {
|
|
|
158
158
|
/** Maximum rate per asset (in wei) */
|
|
159
159
|
maxRate?: bigint;
|
|
160
160
|
/** Minimum maturity timestamp (Unix timestamp in seconds) */
|
|
161
|
-
minMaturity?:
|
|
161
|
+
minMaturity?: Maturity.Maturity;
|
|
162
162
|
/** Maximum maturity timestamp (Unix timestamp in seconds) */
|
|
163
|
-
maxMaturity?:
|
|
163
|
+
maxMaturity?: Maturity.Maturity;
|
|
164
164
|
/** Minimum expiry timestamp (Unix timestamp in seconds) */
|
|
165
165
|
minExpiry?: number;
|
|
166
166
|
/** Maximum expiry timestamp (Unix timestamp in seconds) */
|
|
@@ -173,12 +173,12 @@ type GetParameters = {
|
|
|
173
173
|
collateralTuple?: Array<{
|
|
174
174
|
asset: string;
|
|
175
175
|
oracle?: string;
|
|
176
|
-
lltv?:
|
|
176
|
+
lltv?: LLTV.LLTV;
|
|
177
177
|
}>;
|
|
178
178
|
/** Minimum Loan-to-Value ratio (LLTV) for collateral (percentage as decimal) */
|
|
179
|
-
minLltv?:
|
|
179
|
+
minLltv?: LLTV.LLTV;
|
|
180
180
|
/** Maximum Loan-to-Value ratio (LLTV) for collateral (percentage as decimal) */
|
|
181
|
-
maxLltv?:
|
|
181
|
+
maxLltv?: LLTV.LLTV;
|
|
182
182
|
/** Field to sort results by */
|
|
183
183
|
sortBy?: "rate" | "maturity" | "expiry" | "amount";
|
|
184
184
|
/** Sort direction: asc (ascending) or desc (descending, default) */
|
|
@@ -199,14 +199,14 @@ type MatchParameters = {
|
|
|
199
199
|
collaterals?: Array<{
|
|
200
200
|
asset: string;
|
|
201
201
|
oracle: string;
|
|
202
|
-
lltv:
|
|
202
|
+
lltv: LLTV.LLTV;
|
|
203
203
|
}>;
|
|
204
204
|
/** Exact maturity timestamp (Unix timestamp in seconds) */
|
|
205
|
-
maturity?:
|
|
205
|
+
maturity?: Maturity.Maturity;
|
|
206
206
|
/** Minimum maturity timestamp (Unix timestamp in seconds, inclusive) */
|
|
207
|
-
minMaturity?:
|
|
207
|
+
minMaturity?: Maturity.Maturity;
|
|
208
208
|
/** Maximum maturity timestamp (Unix timestamp in seconds, inclusive) */
|
|
209
|
-
maxMaturity?:
|
|
209
|
+
maxMaturity?: Maturity.Maturity;
|
|
210
210
|
/** The loan asset address to match against */
|
|
211
211
|
loanToken?: string;
|
|
212
212
|
/** Filter by a specific offer creator address */
|
|
@@ -360,8 +360,8 @@ type GetOffersFilters = {
|
|
|
360
360
|
maxAmount?: bigint;
|
|
361
361
|
minRate?: bigint;
|
|
362
362
|
maxRate?: bigint;
|
|
363
|
-
minMaturity?:
|
|
364
|
-
maxMaturity?:
|
|
363
|
+
minMaturity?: Maturity.Maturity;
|
|
364
|
+
maxMaturity?: Maturity.Maturity;
|
|
365
365
|
minExpiry?: number;
|
|
366
366
|
maxExpiry?: number;
|
|
367
367
|
collateralAssets?: string[];
|
|
@@ -369,10 +369,10 @@ type GetOffersFilters = {
|
|
|
369
369
|
collateralTuple?: Array<{
|
|
370
370
|
asset: string;
|
|
371
371
|
oracle?: string;
|
|
372
|
-
lltv?:
|
|
372
|
+
lltv?: LLTV.LLTV;
|
|
373
373
|
}>;
|
|
374
|
-
minLltv?:
|
|
375
|
-
maxLltv?:
|
|
374
|
+
minLltv?: LLTV.LLTV;
|
|
375
|
+
maxLltv?: LLTV.LLTV;
|
|
376
376
|
sortBy?: "rate" | "maturity" | "expiry" | "amount";
|
|
377
377
|
sortOrder?: "asc" | "desc";
|
|
378
378
|
cursor?: string;
|
|
@@ -385,11 +385,11 @@ type FindMatchingOffersParams = {
|
|
|
385
385
|
collaterals?: Array<{
|
|
386
386
|
asset: string;
|
|
387
387
|
oracle: string;
|
|
388
|
-
lltv:
|
|
388
|
+
lltv: LLTV.LLTV;
|
|
389
389
|
}>;
|
|
390
|
-
maturity?:
|
|
391
|
-
minMaturity?:
|
|
392
|
-
maxMaturity?:
|
|
390
|
+
maturity?: Maturity.Maturity;
|
|
391
|
+
minMaturity?: Maturity.Maturity;
|
|
392
|
+
maxMaturity?: Maturity.Maturity;
|
|
393
393
|
loanToken?: string;
|
|
394
394
|
creator?: string;
|
|
395
395
|
/** Filter by offer status; if omitted defaults to ["valid"] */
|
package/dist/index.browser.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as _morpho_dev_mempool from '@morpho-dev/mempool';
|
|
2
|
-
import { Compute, Offer, Errors, Format } from '@morpho-dev/mempool';
|
|
2
|
+
import { Compute, Offer, Errors, Format, Maturity, LLTV } from '@morpho-dev/mempool';
|
|
3
3
|
export * from '@morpho-dev/mempool';
|
|
4
4
|
import * as viem from 'viem';
|
|
5
5
|
import { Address, Hex, PublicClient } from 'viem';
|
|
@@ -158,9 +158,9 @@ type GetParameters = {
|
|
|
158
158
|
/** Maximum rate per asset (in wei) */
|
|
159
159
|
maxRate?: bigint;
|
|
160
160
|
/** Minimum maturity timestamp (Unix timestamp in seconds) */
|
|
161
|
-
minMaturity?:
|
|
161
|
+
minMaturity?: Maturity.Maturity;
|
|
162
162
|
/** Maximum maturity timestamp (Unix timestamp in seconds) */
|
|
163
|
-
maxMaturity?:
|
|
163
|
+
maxMaturity?: Maturity.Maturity;
|
|
164
164
|
/** Minimum expiry timestamp (Unix timestamp in seconds) */
|
|
165
165
|
minExpiry?: number;
|
|
166
166
|
/** Maximum expiry timestamp (Unix timestamp in seconds) */
|
|
@@ -173,12 +173,12 @@ type GetParameters = {
|
|
|
173
173
|
collateralTuple?: Array<{
|
|
174
174
|
asset: string;
|
|
175
175
|
oracle?: string;
|
|
176
|
-
lltv?:
|
|
176
|
+
lltv?: LLTV.LLTV;
|
|
177
177
|
}>;
|
|
178
178
|
/** Minimum Loan-to-Value ratio (LLTV) for collateral (percentage as decimal) */
|
|
179
|
-
minLltv?:
|
|
179
|
+
minLltv?: LLTV.LLTV;
|
|
180
180
|
/** Maximum Loan-to-Value ratio (LLTV) for collateral (percentage as decimal) */
|
|
181
|
-
maxLltv?:
|
|
181
|
+
maxLltv?: LLTV.LLTV;
|
|
182
182
|
/** Field to sort results by */
|
|
183
183
|
sortBy?: "rate" | "maturity" | "expiry" | "amount";
|
|
184
184
|
/** Sort direction: asc (ascending) or desc (descending, default) */
|
|
@@ -199,14 +199,14 @@ type MatchParameters = {
|
|
|
199
199
|
collaterals?: Array<{
|
|
200
200
|
asset: string;
|
|
201
201
|
oracle: string;
|
|
202
|
-
lltv:
|
|
202
|
+
lltv: LLTV.LLTV;
|
|
203
203
|
}>;
|
|
204
204
|
/** Exact maturity timestamp (Unix timestamp in seconds) */
|
|
205
|
-
maturity?:
|
|
205
|
+
maturity?: Maturity.Maturity;
|
|
206
206
|
/** Minimum maturity timestamp (Unix timestamp in seconds, inclusive) */
|
|
207
|
-
minMaturity?:
|
|
207
|
+
minMaturity?: Maturity.Maturity;
|
|
208
208
|
/** Maximum maturity timestamp (Unix timestamp in seconds, inclusive) */
|
|
209
|
-
maxMaturity?:
|
|
209
|
+
maxMaturity?: Maturity.Maturity;
|
|
210
210
|
/** The loan asset address to match against */
|
|
211
211
|
loanToken?: string;
|
|
212
212
|
/** Filter by a specific offer creator address */
|
|
@@ -360,8 +360,8 @@ type GetOffersFilters = {
|
|
|
360
360
|
maxAmount?: bigint;
|
|
361
361
|
minRate?: bigint;
|
|
362
362
|
maxRate?: bigint;
|
|
363
|
-
minMaturity?:
|
|
364
|
-
maxMaturity?:
|
|
363
|
+
minMaturity?: Maturity.Maturity;
|
|
364
|
+
maxMaturity?: Maturity.Maturity;
|
|
365
365
|
minExpiry?: number;
|
|
366
366
|
maxExpiry?: number;
|
|
367
367
|
collateralAssets?: string[];
|
|
@@ -369,10 +369,10 @@ type GetOffersFilters = {
|
|
|
369
369
|
collateralTuple?: Array<{
|
|
370
370
|
asset: string;
|
|
371
371
|
oracle?: string;
|
|
372
|
-
lltv?:
|
|
372
|
+
lltv?: LLTV.LLTV;
|
|
373
373
|
}>;
|
|
374
|
-
minLltv?:
|
|
375
|
-
maxLltv?:
|
|
374
|
+
minLltv?: LLTV.LLTV;
|
|
375
|
+
maxLltv?: LLTV.LLTV;
|
|
376
376
|
sortBy?: "rate" | "maturity" | "expiry" | "amount";
|
|
377
377
|
sortOrder?: "asc" | "desc";
|
|
378
378
|
cursor?: string;
|
|
@@ -385,11 +385,11 @@ type FindMatchingOffersParams = {
|
|
|
385
385
|
collaterals?: Array<{
|
|
386
386
|
asset: string;
|
|
387
387
|
oracle: string;
|
|
388
|
-
lltv:
|
|
388
|
+
lltv: LLTV.LLTV;
|
|
389
389
|
}>;
|
|
390
|
-
maturity?:
|
|
391
|
-
minMaturity?:
|
|
392
|
-
maxMaturity?:
|
|
390
|
+
maturity?: Maturity.Maturity;
|
|
391
|
+
minMaturity?: Maturity.Maturity;
|
|
392
|
+
maxMaturity?: Maturity.Maturity;
|
|
393
393
|
loanToken?: string;
|
|
394
394
|
creator?: string;
|
|
395
395
|
/** Filter by offer status; if omitted defaults to ["valid"] */
|
package/dist/index.browser.js
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
var mempool = require('@morpho-dev/mempool');
|
|
4
4
|
var chains$1 = require('viem/chains');
|
|
5
|
+
var viem = require('viem');
|
|
5
6
|
var v4 = require('zod/v4');
|
|
6
7
|
var zodOpenapi = require('zod-openapi');
|
|
7
|
-
var viem = require('viem');
|
|
8
8
|
|
|
9
9
|
var __defProp = Object.defineProperty;
|
|
10
10
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
@@ -345,19 +345,33 @@ var GetOffersQueryParams = v4.z.object({
|
|
|
345
345
|
example: "1500000000000000000"
|
|
346
346
|
}),
|
|
347
347
|
// Time range
|
|
348
|
-
min_maturity: v4.z.
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
348
|
+
min_maturity: v4.z.coerce.number().int().positive().transform((maturity, ctx) => {
|
|
349
|
+
try {
|
|
350
|
+
return mempool.Maturity.from(maturity);
|
|
351
|
+
} catch (e) {
|
|
352
|
+
ctx.addIssue({
|
|
353
|
+
code: "custom",
|
|
354
|
+
message: e.message
|
|
355
|
+
});
|
|
356
|
+
return v4.z.NEVER;
|
|
357
|
+
}
|
|
358
|
+
}).optional(),
|
|
359
|
+
max_maturity: v4.z.coerce.number().int().positive().transform((maturity, ctx) => {
|
|
360
|
+
try {
|
|
361
|
+
return mempool.Maturity.from(maturity);
|
|
362
|
+
} catch (e) {
|
|
363
|
+
ctx.addIssue({
|
|
364
|
+
code: "custom",
|
|
365
|
+
message: e.message
|
|
366
|
+
});
|
|
367
|
+
return v4.z.NEVER;
|
|
368
|
+
}
|
|
369
|
+
}).optional(),
|
|
370
|
+
min_expiry: v4.z.coerce.number().int().optional().meta({
|
|
357
371
|
description: "Minimum expiry timestamp (Unix timestamp in seconds)",
|
|
358
372
|
example: "1700000000"
|
|
359
373
|
}),
|
|
360
|
-
max_expiry: v4.z.
|
|
374
|
+
max_expiry: v4.z.coerce.number().int().optional().meta({
|
|
361
375
|
description: "Maximum expiry timestamp (Unix timestamp in seconds)",
|
|
362
376
|
example: "1800000000"
|
|
363
377
|
}),
|
|
@@ -379,51 +393,81 @@ var GetOffersQueryParams = v4.z.object({
|
|
|
379
393
|
{
|
|
380
394
|
message: "Collateral tuple must be in format: asset:oracle:lltv#asset2:oracle2:lltv2. Oracle and lltv are optional. Asset must be 0x + 40 hex chars, oracle must be 0x + 40 hex chars, lltv must be a number (e.g., 80.5)."
|
|
381
395
|
}
|
|
382
|
-
).transform((val) => {
|
|
396
|
+
).transform((val, ctx) => {
|
|
383
397
|
return val.split("#").map((tuple) => {
|
|
384
398
|
const parts = tuple.split(":");
|
|
385
399
|
if (parts.length === 0 || !parts[0]) {
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
]);
|
|
400
|
+
ctx.addIssue({
|
|
401
|
+
code: "custom",
|
|
402
|
+
message: "Asset address is required for each collateral tuple",
|
|
403
|
+
path: ["asset"],
|
|
404
|
+
input: val
|
|
405
|
+
});
|
|
406
|
+
return v4.z.NEVER;
|
|
394
407
|
}
|
|
395
408
|
const asset = parts[0]?.toLowerCase();
|
|
396
409
|
const oracle = parts[1]?.toLowerCase();
|
|
397
410
|
const lltv = parts[2] ? parseFloat(parts[2]) : void 0;
|
|
398
411
|
if (lltv !== void 0 && (lltv < MIN_LLTV || lltv > MAX_LLTV)) {
|
|
399
|
-
|
|
400
|
-
|
|
412
|
+
ctx.addIssue({
|
|
413
|
+
code: "custom",
|
|
414
|
+
message: `LLTV must be between ${MIN_LLTV} and ${MAX_LLTV} (0-100%)`,
|
|
415
|
+
path: ["lltv"],
|
|
416
|
+
input: val
|
|
417
|
+
});
|
|
418
|
+
return v4.z.NEVER;
|
|
419
|
+
}
|
|
420
|
+
let lltvValue;
|
|
421
|
+
if (lltv !== void 0) {
|
|
422
|
+
try {
|
|
423
|
+
lltvValue = mempool.LLTV.from(viem.parseUnits(lltv.toString(), 16));
|
|
424
|
+
} catch (e) {
|
|
425
|
+
ctx.issues.push({
|
|
401
426
|
code: "custom",
|
|
402
|
-
message:
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
}
|
|
406
|
-
|
|
427
|
+
message: e instanceof mempool.LLTV.InvalidLLTVError || e instanceof mempool.LLTV.InvalidOptionError ? e.message : "Invalid LLTV.",
|
|
428
|
+
input: lltv,
|
|
429
|
+
path: ["lltv"]
|
|
430
|
+
});
|
|
431
|
+
return v4.z.NEVER;
|
|
432
|
+
}
|
|
407
433
|
}
|
|
408
434
|
return {
|
|
409
435
|
asset,
|
|
410
436
|
oracle,
|
|
411
|
-
lltv
|
|
437
|
+
lltv: lltvValue
|
|
412
438
|
};
|
|
413
439
|
});
|
|
414
440
|
}).optional().meta({
|
|
415
441
|
description: "Filter by collateral combinations in format: asset:oracle:lltv#asset2:oracle2:lltv2. Oracle and lltv are optional. Use # to separate multiple combinations.",
|
|
416
|
-
example: "0x1234567890123456789012345678901234567890:0xabcdefabcdefabcdefabcdefabcdefabcdefabcd:
|
|
442
|
+
example: "0x1234567890123456789012345678901234567890:0xabcdefabcdefabcdefabcdefabcdefabcdefabcd:86#0x9876543210987654321098765432109876543210:94.5"
|
|
417
443
|
}),
|
|
418
|
-
min_lltv: v4.z.
|
|
419
|
-
|
|
420
|
-
|
|
444
|
+
min_lltv: v4.z.coerce.number().min(0, { message: "LLTV must be above 0" }).max(100, { message: "LLTV must be below 100" }).transform((lltv, ctx) => {
|
|
445
|
+
try {
|
|
446
|
+
return mempool.LLTV.from(viem.parseUnits(lltv.toString(), 16));
|
|
447
|
+
} catch (e) {
|
|
448
|
+
ctx.addIssue({
|
|
449
|
+
code: "custom",
|
|
450
|
+
message: e.message,
|
|
451
|
+
input: lltv
|
|
452
|
+
});
|
|
453
|
+
return v4.z.NEVER;
|
|
454
|
+
}
|
|
455
|
+
}).optional().meta({
|
|
421
456
|
description: "Minimum Loan-to-Value ratio (LLTV) for collateral (percentage as decimal, e.g., 80.5 = 80.5%)",
|
|
422
457
|
example: "80.5"
|
|
423
458
|
}),
|
|
424
|
-
max_lltv: v4.z.
|
|
425
|
-
|
|
426
|
-
|
|
459
|
+
max_lltv: v4.z.coerce.number().min(0, { message: "LLTV must be above 0" }).max(100, { message: "LLTV must be below 100" }).transform((lltv, ctx) => {
|
|
460
|
+
try {
|
|
461
|
+
return mempool.LLTV.from(viem.parseUnits(lltv.toString(), 16));
|
|
462
|
+
} catch (e) {
|
|
463
|
+
ctx.addIssue({
|
|
464
|
+
code: "custom",
|
|
465
|
+
message: e.message,
|
|
466
|
+
input: lltv
|
|
467
|
+
});
|
|
468
|
+
return v4.z.NEVER;
|
|
469
|
+
}
|
|
470
|
+
}).optional().meta({
|
|
427
471
|
description: "Maximum Loan-to-Value ratio (LLTV) for collateral (percentage as decimal, e.g., 95.5 = 95.5%)",
|
|
428
472
|
example: "95.5"
|
|
429
473
|
}),
|
|
@@ -516,68 +560,89 @@ var MatchOffersQueryParams = v4.z.object({
|
|
|
516
560
|
}),
|
|
517
561
|
// Collateral filtering
|
|
518
562
|
collaterals: v4.z.string().regex(
|
|
519
|
-
/^(0x[a-fA-F0-9]{40}:0x[a-fA-F0-9]{40}
|
|
563
|
+
/^(0x[a-fA-F0-9]{40}:0x[a-fA-F0-9]{40}:[0-9]+(\.[0-9]+)?)(#0x[a-fA-F0-9]{40}:0x[a-fA-F0-9]{40}:[0-9]+(\.[0-9]+)?)*$/,
|
|
520
564
|
{
|
|
521
565
|
message: "Collaterals must be in format: asset:oracle:lltv#asset2:oracle2:lltv2. All fields are required for each collateral."
|
|
522
566
|
}
|
|
523
|
-
).transform((val) => {
|
|
567
|
+
).transform((val, ctx) => {
|
|
524
568
|
return val.split("#").map((collateral) => {
|
|
525
569
|
const parts = collateral.split(":");
|
|
526
570
|
if (parts.length !== 3) {
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
]);
|
|
571
|
+
ctx.addIssue({
|
|
572
|
+
code: "custom",
|
|
573
|
+
message: "Each collateral must have exactly 3 parts: asset:oracle:lltv",
|
|
574
|
+
path: ["collaterals"],
|
|
575
|
+
input: val
|
|
576
|
+
});
|
|
577
|
+
return v4.z.NEVER;
|
|
535
578
|
}
|
|
536
579
|
const [asset, oracle, lltvStr] = parts;
|
|
537
580
|
if (!asset || !oracle || !lltvStr) {
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
}
|
|
545
|
-
]);
|
|
581
|
+
ctx.addIssue({
|
|
582
|
+
code: "custom",
|
|
583
|
+
message: "Asset, oracle, and lltv are all required for each collateral",
|
|
584
|
+
path: ["collaterals"],
|
|
585
|
+
input: val
|
|
586
|
+
});
|
|
546
587
|
}
|
|
547
|
-
|
|
548
|
-
if (
|
|
549
|
-
|
|
550
|
-
|
|
588
|
+
let lltvValue;
|
|
589
|
+
if (lltvStr !== void 0) {
|
|
590
|
+
try {
|
|
591
|
+
lltvValue = mempool.LLTV.from(viem.parseUnits(lltvStr, 16));
|
|
592
|
+
} catch (e) {
|
|
593
|
+
ctx.issues.push({
|
|
551
594
|
code: "custom",
|
|
552
|
-
message:
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
}
|
|
556
|
-
|
|
595
|
+
message: e instanceof mempool.LLTV.InvalidLLTVError || e instanceof mempool.LLTV.InvalidOptionError ? e.message : "Invalid LLTV.",
|
|
596
|
+
input: lltvStr,
|
|
597
|
+
path: ["lltv"]
|
|
598
|
+
});
|
|
599
|
+
return v4.z.NEVER;
|
|
600
|
+
}
|
|
557
601
|
}
|
|
558
602
|
return {
|
|
559
603
|
asset: asset.toLowerCase(),
|
|
560
604
|
oracle: oracle.toLowerCase(),
|
|
561
|
-
lltv
|
|
605
|
+
lltv: lltvValue
|
|
562
606
|
};
|
|
563
607
|
});
|
|
564
608
|
}).optional().meta({
|
|
565
609
|
description: "Collateral requirements in format: asset:oracle:lltv#asset2:oracle2:lltv2. Use # to separate multiple collaterals.",
|
|
566
|
-
example: "0x1234567890123456789012345678901234567890:0xabcdefabcdefabcdefabcdefabcdefabcdefabcd:
|
|
610
|
+
example: "0x1234567890123456789012345678901234567890:0xabcdefabcdefabcdefabcdefabcdefabcdefabcd:86#0x9876543210987654321098765432109876543210:0xfedcbafedcbafedcbafedcbafedcbafedcbafedc:94.5"
|
|
567
611
|
}),
|
|
568
612
|
// Maturity filtering
|
|
569
|
-
maturity: v4.z.
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
613
|
+
maturity: v4.z.coerce.number().int().positive().transform((maturity, ctx) => {
|
|
614
|
+
try {
|
|
615
|
+
return mempool.Maturity.from(maturity);
|
|
616
|
+
} catch (e) {
|
|
617
|
+
ctx.addIssue({
|
|
618
|
+
code: "custom",
|
|
619
|
+
message: e.message
|
|
620
|
+
});
|
|
621
|
+
return v4.z.NEVER;
|
|
622
|
+
}
|
|
623
|
+
}).optional(),
|
|
624
|
+
min_maturity: v4.z.coerce.number().int().positive().transform((maturity, ctx) => {
|
|
625
|
+
try {
|
|
626
|
+
return mempool.Maturity.from(maturity);
|
|
627
|
+
} catch (e) {
|
|
628
|
+
ctx.addIssue({
|
|
629
|
+
code: "custom",
|
|
630
|
+
message: e.message
|
|
631
|
+
});
|
|
632
|
+
return v4.z.NEVER;
|
|
633
|
+
}
|
|
634
|
+
}).optional(),
|
|
635
|
+
max_maturity: v4.z.coerce.number().int().positive().transform((maturity, ctx) => {
|
|
636
|
+
try {
|
|
637
|
+
return mempool.Maturity.from(maturity);
|
|
638
|
+
} catch (e) {
|
|
639
|
+
ctx.addIssue({
|
|
640
|
+
code: "custom",
|
|
641
|
+
message: e.message
|
|
642
|
+
});
|
|
643
|
+
return v4.z.NEVER;
|
|
644
|
+
}
|
|
645
|
+
}).optional(),
|
|
581
646
|
// Asset and creator filtering
|
|
582
647
|
loan_token: v4.z.string().regex(/^0x[a-fA-F0-9]{40}$/, {
|
|
583
648
|
message: "Loan asset must be a valid Ethereum address"
|
|
@@ -639,8 +704,10 @@ var schemas = {
|
|
|
639
704
|
get_offers: GetOffersQueryParams,
|
|
640
705
|
match_offers: MatchOffersQueryParams
|
|
641
706
|
};
|
|
642
|
-
function safeParse(action, query) {
|
|
643
|
-
return schemas[action].safeParse(query
|
|
707
|
+
function safeParse(action, query, error) {
|
|
708
|
+
return schemas[action].safeParse(query, {
|
|
709
|
+
error
|
|
710
|
+
});
|
|
644
711
|
}
|
|
645
712
|
|
|
646
713
|
// src/core/apiSchema/openapi.ts
|
|
@@ -692,7 +759,7 @@ var paths = {
|
|
|
692
759
|
}
|
|
693
760
|
}
|
|
694
761
|
},
|
|
695
|
-
"/v1/match
|
|
762
|
+
"/v1/offers/match": {
|
|
696
763
|
get: {
|
|
697
764
|
summary: "Match offers",
|
|
698
765
|
description: "Find offers that match specific criteria",
|
|
@@ -843,16 +910,16 @@ async function get(config, parameters) {
|
|
|
843
910
|
} else if (lltv !== void 0) {
|
|
844
911
|
result += `:`;
|
|
845
912
|
}
|
|
846
|
-
if (lltv !== void 0) result += `:${lltv}`;
|
|
913
|
+
if (lltv !== void 0) result += `:${viem.formatUnits(lltv, 16)}`;
|
|
847
914
|
return result;
|
|
848
915
|
}).join("#");
|
|
849
916
|
url.searchParams.set("collateral_tuple", tupleStr);
|
|
850
917
|
}
|
|
851
918
|
if (parameters.minLltv !== void 0) {
|
|
852
|
-
url.searchParams.set("min_lltv", parameters.minLltv
|
|
919
|
+
url.searchParams.set("min_lltv", viem.formatUnits(parameters.minLltv, 16));
|
|
853
920
|
}
|
|
854
921
|
if (parameters.maxLltv !== void 0) {
|
|
855
|
-
url.searchParams.set("max_lltv", parameters.maxLltv
|
|
922
|
+
url.searchParams.set("max_lltv", viem.formatUnits(parameters.maxLltv, 16));
|
|
856
923
|
}
|
|
857
924
|
if (parameters.sortBy) {
|
|
858
925
|
url.searchParams.set("sort_by", parameters.sortBy);
|
|
@@ -874,14 +941,14 @@ async function get(config, parameters) {
|
|
|
874
941
|
};
|
|
875
942
|
}
|
|
876
943
|
async function match(config, parameters) {
|
|
877
|
-
const url = new URL(`${config.url.toString()}v1/match
|
|
944
|
+
const url = new URL(`${config.url.toString()}v1/offers/match`);
|
|
878
945
|
url.searchParams.set("side", parameters.side);
|
|
879
946
|
url.searchParams.set("chain_id", parameters.chainId.toString());
|
|
880
947
|
if (parameters.rate !== void 0) {
|
|
881
948
|
url.searchParams.set("rate", parameters.rate.toString());
|
|
882
949
|
}
|
|
883
950
|
if (parameters.collaterals?.length) {
|
|
884
|
-
const collateralsStr = parameters.collaterals.map(({ asset, oracle, lltv }) => `${asset}:${oracle}:${lltv}`).join("#");
|
|
951
|
+
const collateralsStr = parameters.collaterals.map(({ asset, oracle, lltv }) => `${asset}:${oracle}:${viem.formatUnits(lltv, 16)}`).join("#");
|
|
885
952
|
url.searchParams.set("collaterals", collateralsStr);
|
|
886
953
|
}
|
|
887
954
|
if (parameters.maturity !== void 0) {
|
|
@@ -922,7 +989,7 @@ async function getApi(config, url) {
|
|
|
922
989
|
case pathname.includes("/v1/offers"):
|
|
923
990
|
action = "get_offers";
|
|
924
991
|
break;
|
|
925
|
-
case pathname.includes("/v1/match
|
|
992
|
+
case pathname.includes("/v1/offers/match"):
|
|
926
993
|
action = "match_offers";
|
|
927
994
|
break;
|
|
928
995
|
default:
|
|
@@ -1135,6 +1202,7 @@ function memory(parameters) {
|
|
|
1135
1202
|
}
|
|
1136
1203
|
creators && (creators = creators.map((c) => c.toLowerCase()));
|
|
1137
1204
|
loanTokens && (loanTokens = loanTokens.map((lt) => lt.toLowerCase()));
|
|
1205
|
+
callbackAddresses && (callbackAddresses = callbackAddresses.map((ca) => ca.toLowerCase()));
|
|
1138
1206
|
collateralAssets && (collateralAssets = collateralAssets.map((ca) => ca.toLowerCase()));
|
|
1139
1207
|
collateralOracles && (collateralOracles = collateralOracles.map((co) => co.toLowerCase()));
|
|
1140
1208
|
collateralTuple && (collateralTuple = collateralTuple.map((ct) => ({
|
|
@@ -1171,12 +1239,8 @@ function memory(parameters) {
|
|
|
1171
1239
|
)
|
|
1172
1240
|
)
|
|
1173
1241
|
));
|
|
1174
|
-
minLltv && (offers = offers.filter(
|
|
1175
|
-
|
|
1176
|
-
));
|
|
1177
|
-
maxLltv && (offers = offers.filter(
|
|
1178
|
-
(o) => o.collaterals.every((c) => c.lltv <= mempool.LLTV.from(viem.parseUnits(maxLltv.toString(), 16)))
|
|
1179
|
-
));
|
|
1242
|
+
minLltv && (offers = offers.filter((o) => o.collaterals.every((c) => c.lltv >= minLltv)));
|
|
1243
|
+
maxLltv && (offers = offers.filter((o) => o.collaterals.every((c) => c.lltv <= maxLltv)));
|
|
1180
1244
|
offers = offers.sort((a, b) => sort(sortBy, sortOrder, a, b));
|
|
1181
1245
|
let nextCursor = null;
|
|
1182
1246
|
if (offers.length > limit) {
|
|
@@ -1223,8 +1287,8 @@ function memory(parameters) {
|
|
|
1223
1287
|
limit = 20
|
|
1224
1288
|
} = params;
|
|
1225
1289
|
const now = mempool.Time.now();
|
|
1226
|
-
const
|
|
1227
|
-
const sortOrder =
|
|
1290
|
+
const isBuying = side === "buy";
|
|
1291
|
+
const sortOrder = isBuying ? "desc" : "asc";
|
|
1228
1292
|
let offers = Array.from(map.values()).map((o) => ({
|
|
1229
1293
|
...o,
|
|
1230
1294
|
consumed: filled.get(o.chainId)?.get(o.offering.toLowerCase())?.get(o.nonce) || 0n
|
|
@@ -1237,22 +1301,27 @@ function memory(parameters) {
|
|
|
1237
1301
|
offers = offers.filter(
|
|
1238
1302
|
(o) => sortOrder === "asc" ? o.rate >= BigInt(cursor.rate) : o.rate <= BigInt(cursor.rate)
|
|
1239
1303
|
);
|
|
1240
|
-
offers = offers.filter((o) => o.hash !== cursor.hash);
|
|
1241
1304
|
}
|
|
1242
|
-
offers = offers.filter((o) => o.buy ===
|
|
1305
|
+
offers = offers.filter((o) => o.buy === !isBuying);
|
|
1243
1306
|
offers = offers.filter((o) => o.chainId === BigInt(chainId));
|
|
1244
1307
|
offers = offers.filter((o) => o.expiry >= now);
|
|
1245
|
-
rate && (offers = offers.filter((o) =>
|
|
1308
|
+
rate && (offers = offers.filter((o) => isBuying ? o.rate >= rate : o.rate <= rate));
|
|
1246
1309
|
collaterals.length > 0 && (offers = offers.filter(
|
|
1247
|
-
(o) =>
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1310
|
+
(o) => isBuying ? (
|
|
1311
|
+
// when wanting to buy, sell offer collaterals ⊆ user buy collaterals
|
|
1312
|
+
o.collaterals.every((oc) => {
|
|
1313
|
+
return collaterals.some(
|
|
1314
|
+
(c) => oc.asset.toLowerCase() === c.asset.toLowerCase() && oc.oracle.toLowerCase() === c.oracle.toLowerCase() && oc.lltv === c.lltv
|
|
1315
|
+
);
|
|
1316
|
+
})
|
|
1317
|
+
) : (
|
|
1318
|
+
// when wanting to sell, user sell collaterals ⊆ buy offer collaterals
|
|
1319
|
+
collaterals.every((c) => {
|
|
1320
|
+
return o.collaterals.some(
|
|
1321
|
+
(oc) => oc.asset.toLowerCase() === c.asset.toLowerCase() && oc.oracle.toLowerCase() === c.oracle.toLowerCase() && oc.lltv === c.lltv
|
|
1322
|
+
);
|
|
1323
|
+
})
|
|
1324
|
+
)
|
|
1256
1325
|
));
|
|
1257
1326
|
maturity && (offers = offers.filter((o) => o.maturity === maturity));
|
|
1258
1327
|
minMaturity && (offers = offers.filter((o) => o.maturity >= minMaturity));
|
|
@@ -1290,6 +1359,7 @@ function memory(parameters) {
|
|
|
1290
1359
|
}
|
|
1291
1360
|
offers = Array.from(byGroup.values());
|
|
1292
1361
|
offers = offers.sort((a, b) => sort("rate", sortOrder, a, b));
|
|
1362
|
+
cursor && (offers = offers.filter((o) => o.hash !== cursor.hash));
|
|
1293
1363
|
let nextCursor = null;
|
|
1294
1364
|
if (offers.length > limit) {
|
|
1295
1365
|
const last = offers[limit - 1];
|
|
@@ -1322,9 +1392,12 @@ function memory(parameters) {
|
|
|
1322
1392
|
return deleted;
|
|
1323
1393
|
},
|
|
1324
1394
|
updateStatus: async (parameters2) => {
|
|
1325
|
-
|
|
1326
|
-
map.
|
|
1327
|
-
|
|
1395
|
+
const key = parameters2.offerHash.toLowerCase();
|
|
1396
|
+
const existing = map.get(key);
|
|
1397
|
+
if (!existing) return;
|
|
1398
|
+
if (existing.status === parameters2.status) return;
|
|
1399
|
+
map.set(key, {
|
|
1400
|
+
...existing,
|
|
1328
1401
|
status: parameters2.status,
|
|
1329
1402
|
metadata: parameters2.metadata
|
|
1330
1403
|
});
|