@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.
@@ -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?: number;
161
+ minMaturity?: Maturity.Maturity;
162
162
  /** Maximum maturity timestamp (Unix timestamp in seconds) */
163
- maxMaturity?: number;
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?: number;
176
+ lltv?: LLTV.LLTV;
177
177
  }>;
178
178
  /** Minimum Loan-to-Value ratio (LLTV) for collateral (percentage as decimal) */
179
- minLltv?: number;
179
+ minLltv?: LLTV.LLTV;
180
180
  /** Maximum Loan-to-Value ratio (LLTV) for collateral (percentage as decimal) */
181
- maxLltv?: number;
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: bigint;
202
+ lltv: LLTV.LLTV;
203
203
  }>;
204
204
  /** Exact maturity timestamp (Unix timestamp in seconds) */
205
- maturity?: number;
205
+ maturity?: Maturity.Maturity;
206
206
  /** Minimum maturity timestamp (Unix timestamp in seconds, inclusive) */
207
- minMaturity?: number;
207
+ minMaturity?: Maturity.Maturity;
208
208
  /** Maximum maturity timestamp (Unix timestamp in seconds, inclusive) */
209
- maxMaturity?: number;
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?: number;
364
- maxMaturity?: number;
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?: number;
372
+ lltv?: LLTV.LLTV;
373
373
  }>;
374
- minLltv?: number;
375
- maxLltv?: number;
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: bigint;
388
+ lltv: LLTV.LLTV;
389
389
  }>;
390
- maturity?: number;
391
- minMaturity?: number;
392
- maxMaturity?: number;
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"] */
@@ -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?: number;
161
+ minMaturity?: Maturity.Maturity;
162
162
  /** Maximum maturity timestamp (Unix timestamp in seconds) */
163
- maxMaturity?: number;
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?: number;
176
+ lltv?: LLTV.LLTV;
177
177
  }>;
178
178
  /** Minimum Loan-to-Value ratio (LLTV) for collateral (percentage as decimal) */
179
- minLltv?: number;
179
+ minLltv?: LLTV.LLTV;
180
180
  /** Maximum Loan-to-Value ratio (LLTV) for collateral (percentage as decimal) */
181
- maxLltv?: number;
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: bigint;
202
+ lltv: LLTV.LLTV;
203
203
  }>;
204
204
  /** Exact maturity timestamp (Unix timestamp in seconds) */
205
- maturity?: number;
205
+ maturity?: Maturity.Maturity;
206
206
  /** Minimum maturity timestamp (Unix timestamp in seconds, inclusive) */
207
- minMaturity?: number;
207
+ minMaturity?: Maturity.Maturity;
208
208
  /** Maximum maturity timestamp (Unix timestamp in seconds, inclusive) */
209
- maxMaturity?: number;
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?: number;
364
- maxMaturity?: number;
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?: number;
372
+ lltv?: LLTV.LLTV;
373
373
  }>;
374
- minLltv?: number;
375
- maxLltv?: number;
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: bigint;
388
+ lltv: LLTV.LLTV;
389
389
  }>;
390
- maturity?: number;
391
- minMaturity?: number;
392
- maxMaturity?: number;
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"] */
@@ -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.bigint({ coerce: true }).min(0n).optional().transform((val) => val === void 0 ? void 0 : Number(val)).meta({
349
- description: "Minimum maturity timestamp (Unix timestamp in seconds)",
350
- example: "1700000000"
351
- }),
352
- max_maturity: v4.z.bigint({ coerce: true }).min(0n).optional().transform((val) => val === void 0 ? void 0 : Number(val)).meta({
353
- description: "Maximum maturity timestamp (Unix timestamp in seconds)",
354
- example: "1800000000"
355
- }),
356
- min_expiry: v4.z.bigint({ coerce: true }).min(0n).optional().transform((val) => val === void 0 ? void 0 : Number(val)).meta({
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.bigint({ coerce: true }).min(0n).optional().transform((val) => val === void 0 ? void 0 : Number(val)).meta({
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
- throw new v4.z.ZodError([
387
- {
388
- code: "custom",
389
- message: "Asset address is required for each collateral tuple",
390
- path: ["collateral_tuple"],
391
- input: val
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
- throw new v4.z.ZodError([
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: `LLTV must be between ${MIN_LLTV} and ${MAX_LLTV} (0-100%)`,
403
- path: ["collateral_tuple"],
404
- input: val
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:8000#0x9876543210987654321098765432109876543210::8000"
442
+ example: "0x1234567890123456789012345678901234567890:0xabcdefabcdefabcdefabcdefabcdefabcdefabcd:86#0x9876543210987654321098765432109876543210:94.5"
417
443
  }),
418
- min_lltv: v4.z.string().regex(/^\d+(\.\d+)?$/, {
419
- message: "Min LLTV must be a valid number"
420
- }).transform((val) => parseFloat(val)).pipe(v4.z.number().min(0).max(100)).optional().meta({
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.string().regex(/^\d+(\.\d+)?$/, {
425
- message: "Max LLTV must be a valid number"
426
- }).transform((val) => parseFloat(val)).pipe(v4.z.number().min(0).max(100)).optional().meta({
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}:\d+)(#0x[a-fA-F0-9]{40}:0x[a-fA-F0-9]{40}:\d+)*$/,
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
- throw new v4.z.ZodError([
528
- {
529
- code: "custom",
530
- message: "Each collateral must have exactly 3 parts: asset:oracle:lltv",
531
- path: ["collaterals"],
532
- input: val
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
- throw new v4.z.ZodError([
539
- {
540
- code: "custom",
541
- message: "Asset, oracle, and lltv are all required for each collateral",
542
- path: ["collaterals"],
543
- input: val
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
- const lltv = BigInt(lltvStr);
548
- if (lltv <= 0n) {
549
- throw new v4.z.ZodError([
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: "LLTV must be a positive number",
553
- path: ["collaterals"],
554
- input: val
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:800000000000000000#0x9876543210987654321098765432109876543210:0xfedcbafedcbafedcbafedcbafedcbafedcbafedc:900000000000000000"
610
+ example: "0x1234567890123456789012345678901234567890:0xabcdefabcdefabcdefabcdefabcdefabcdefabcd:86#0x9876543210987654321098765432109876543210:0xfedcbafedcbafedcbafedcbafedcbafedcbafedc:94.5"
567
611
  }),
568
612
  // Maturity filtering
569
- maturity: v4.z.bigint({ coerce: true }).min(0n).optional().transform((val) => val === void 0 ? void 0 : Number(val)).meta({
570
- description: "Exact maturity timestamp (Unix timestamp in seconds)",
571
- example: "1700000000"
572
- }),
573
- min_maturity: v4.z.bigint({ coerce: true }).min(0n).optional().transform((val) => val === void 0 ? void 0 : Number(val)).meta({
574
- description: "Minimum maturity timestamp (Unix timestamp in seconds, inclusive)",
575
- example: "1700000000"
576
- }),
577
- max_maturity: v4.z.bigint({ coerce: true }).min(0n).optional().transform((val) => val === void 0 ? void 0 : Number(val)).meta({
578
- description: "Maximum maturity timestamp (Unix timestamp in seconds, inclusive)",
579
- example: "1800000000"
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-offers": {
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.toString());
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.toString());
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-offers`);
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-offers"):
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
- (o) => o.collaterals.every((c) => c.lltv >= mempool.LLTV.from(viem.parseUnits(minLltv.toString(), 16)))
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 buy = side !== "buy";
1227
- const sortOrder = buy ? "asc" : "desc";
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 === 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) => buy ? o.rate >= rate : o.rate <= rate));
1308
+ rate && (offers = offers.filter((o) => isBuying ? o.rate >= rate : o.rate <= rate));
1246
1309
  collaterals.length > 0 && (offers = offers.filter(
1247
- (o) => buy ? collaterals.every((c) => {
1248
- return o.collaterals.some(
1249
- (oc) => oc.asset.toLowerCase() === c.asset.toLowerCase() && oc.oracle.toLowerCase() === c.oracle.toLowerCase() && oc.lltv === c.lltv
1250
- );
1251
- }) : o.collaterals.every((oc) => {
1252
- return collaterals.some(
1253
- (c) => oc.asset.toLowerCase() === c.asset.toLowerCase() && oc.oracle.toLowerCase() === c.oracle.toLowerCase() && oc.lltv === c.lltv
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
- if (!map.has(parameters2.offerHash.toLowerCase())) return;
1326
- map.set(parameters2.offerHash.toLowerCase(), {
1327
- ...map.get(parameters2.offerHash.toLowerCase()),
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
  });