@leather.io/models 0.45.0 → 0.47.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/index.js CHANGED
@@ -1,29 +1,54 @@
1
- // src/assets/asset.model.ts
2
- var CryptoAssetChains = {
3
- bitcoin: "bitcoin",
4
- stacks: "stacks"
1
+ // src/account.model.ts
2
+ import { z } from "zod";
3
+ var walletIdSchema = z.object({
4
+ fingerprint: z.string()
5
+ });
6
+ var accountIdSchema = walletIdSchema.and(z.object({ accountIndex: z.number() }));
7
+ var bitcoinAddressInfoSchema = z.object({
8
+ taprootDescriptor: z.string(),
9
+ nativeSegwitDescriptor: z.string(),
10
+ zeroIndexTaprootPayerAddress: z.string().optional(),
11
+ zeroIndexNativeSegwitPayerAddress: z.string().optional()
12
+ });
13
+ var stacksAddressInfoSchema = z.object({
14
+ stxAddress: z.string()
15
+ });
16
+ var accountAddressesSchema = z.object({
17
+ id: accountIdSchema,
18
+ bitcoin: bitcoinAddressInfoSchema.optional(),
19
+ stacks: stacksAddressInfoSchema.optional()
20
+ });
21
+
22
+ // src/activity/activity-level.model.ts
23
+ var ActivityLevels = {
24
+ account: "account",
25
+ app: "app"
5
26
  };
6
- var CryptoAssetCategories = {
7
- fungible: "fungible",
8
- nft: "nft"
27
+
28
+ // src/activity/activity-status.model.ts
29
+ var OnChainActivityStatuses = {
30
+ pending: "pending",
31
+ success: "success",
32
+ failed: "failed"
9
33
  };
10
- var FungibleCryptoAssetProtocols = {
11
- nativeBtc: "nativeBtc",
12
- nativeStx: "nativeStx",
13
- sip10: "sip10",
14
- brc20: "brc20",
15
- src20: "src20",
16
- stx20: "stx20",
17
- rune: "rune"
34
+
35
+ // src/activity/activity-type.model.ts
36
+ var OnChainActivityTypes = {
37
+ deploySmartContract: "deploySmartContract",
38
+ executeSmartContract: "executeSmartContract",
39
+ lockAsset: "lockAsset",
40
+ sendAsset: "sendAsset",
41
+ receiveAsset: "receiveAsset",
42
+ swapAssets: "swapAssets"
18
43
  };
19
- var NonFungibleCryptoAssetProtocols = {
20
- stamp: "stamp",
21
- sip9: "sip9",
22
- inscription: "inscription"
44
+ var WalletActivityTypes = {
45
+ connectApp: "connectApp",
46
+ signMessage: "signMessage"
23
47
  };
24
- var CryptoAssetProtocols = {
25
- ...FungibleCryptoAssetProtocols,
26
- ...NonFungibleCryptoAssetProtocols
48
+ var GeneralActivityTypes = {
49
+ walletAdded: "walletAdded",
50
+ receiveAnnouncement: "receiveAnnouncement",
51
+ featureWaitlistNotification: "featureWaitlistNotification"
27
52
  };
28
53
 
29
54
  // src/assets/asset-type-guards.ts
@@ -70,6 +95,34 @@ function isSip9Asset(asset) {
70
95
  return asset.protocol === "sip9";
71
96
  }
72
97
 
98
+ // src/assets/asset.model.ts
99
+ var CryptoAssetChains = {
100
+ bitcoin: "bitcoin",
101
+ stacks: "stacks"
102
+ };
103
+ var CryptoAssetCategories = {
104
+ fungible: "fungible",
105
+ nft: "nft"
106
+ };
107
+ var FungibleCryptoAssetProtocols = {
108
+ nativeBtc: "nativeBtc",
109
+ nativeStx: "nativeStx",
110
+ sip10: "sip10",
111
+ brc20: "brc20",
112
+ src20: "src20",
113
+ stx20: "stx20",
114
+ rune: "rune"
115
+ };
116
+ var NonFungibleCryptoAssetProtocols = {
117
+ stamp: "stamp",
118
+ sip9: "sip9",
119
+ inscription: "inscription"
120
+ };
121
+ var CryptoAssetProtocols = {
122
+ ...FungibleCryptoAssetProtocols,
123
+ ...NonFungibleCryptoAssetProtocols
124
+ };
125
+
73
126
  // src/assets/sip9-asset.model.ts
74
127
  var sip9ContentTypes = [
75
128
  "image/jpeg",
@@ -111,17 +164,16 @@ var sip9ContentTypes = [
111
164
  ""
112
165
  ];
113
166
 
114
- // src/inscription-mime-type.model.ts
115
- var inscriptionMimeTypes = [
116
- "audio",
117
- "gltf",
118
- "html",
119
- "image",
120
- "svg",
121
- "text",
122
- "video",
123
- "other"
124
- ];
167
+ // src/bitcoin.model.ts
168
+ import { z as z2 } from "zod";
169
+ var bitcoinUnitSchema = z2.enum(["bitcoin", "satoshi"]);
170
+
171
+ // src/bns.model.ts
172
+ var bnsContractAddress = {
173
+ mainnet: "SP2QEZ06AGJ3RKJPBV14SY1V5BBFNAW33D96YPGZF",
174
+ testnet: "ST2QEZ06AGJ3RKJPBV14SY1V5BBFNAW33D9SZJQ0M"
175
+ };
176
+ var bnsContractName = "BNS-V2";
125
177
 
126
178
  // src/fees/bitcoin-fees.model.ts
127
179
  var btcTxTimeMap = {
@@ -154,6 +206,27 @@ var FeeCalculationTypes = /* @__PURE__ */ ((FeeCalculationTypes2) => {
154
206
  return FeeCalculationTypes2;
155
207
  })(FeeCalculationTypes || {});
156
208
 
209
+ // src/fees/transaction-fees.model.ts
210
+ var transactionFeeTiers = ["low", "standard", "high"];
211
+ var transactionFeeQuoteType = [
212
+ "flat",
213
+ "bitcoinFeeRate",
214
+ "stacksFeeRate",
215
+ "evm1559"
216
+ ];
217
+
218
+ // src/inscription-mime-type.model.ts
219
+ var inscriptionMimeTypes = [
220
+ "audio",
221
+ "gltf",
222
+ "html",
223
+ "image",
224
+ "svg",
225
+ "text",
226
+ "video",
227
+ "other"
228
+ ];
229
+
157
230
  // src/market.model.ts
158
231
  function createMarketPair(base, quote) {
159
232
  return Object.freeze({ base, quote });
@@ -166,8 +239,10 @@ function createMarketData(pair, price) {
166
239
  throw new Error("Cannot create market data when price does not match quote");
167
240
  return Object.freeze({ pair, price });
168
241
  }
242
+ var historicalPeriods = ["1d", "1w", "1m", "3m", "6m", "1y"];
169
243
 
170
244
  // src/network/network.model.ts
245
+ import { z as z3 } from "zod";
171
246
  var HIRO_API_BASE_URL_MAINNET = "https://api.hiro.so";
172
247
  var HIRO_API_BASE_URL_TESTNET = "https://api.testnet.hiro.so";
173
248
  var HIRO_API_BASE_URL_NAKAMOTO_TESTNET = "https://api.nakamoto.testnet.hiro.so";
@@ -196,6 +271,15 @@ var WalletDefaultNetworkConfigurationIds = /* @__PURE__ */ ((WalletDefaultNetwor
196
271
  WalletDefaultNetworkConfigurationIds2["devnet"] = "devnet";
197
272
  return WalletDefaultNetworkConfigurationIds2;
198
273
  })(WalletDefaultNetworkConfigurationIds || {});
274
+ var defaultNetworkConfigurationsSchema = z3.enum([
275
+ "mainnet",
276
+ "testnet",
277
+ "testnet4",
278
+ "signet",
279
+ "sbtcTestnet",
280
+ "sbtcDevenv",
281
+ "devnet"
282
+ ]);
199
283
  var supportedBlockchains = ["stacks", "bitcoin"];
200
284
  var networkModes = ["mainnet", "testnet"];
201
285
  var testnetModes = ["testnet", "regtest", "signet"];
@@ -347,95 +431,197 @@ var defaultNetworksKeyedById = {
347
431
  };
348
432
 
349
433
  // src/network/network.schema.ts
350
- import { z } from "zod";
351
- var bitcoinNetworkModesSchema = z.enum([...networkModes, ...testnetModes]);
352
- var bitcoinNetworkSchema = z.enum([...bitcoinNetworks]);
353
- var networkConfigurationSchema = z.object({
354
- name: z.string(),
355
- id: z.string(),
356
- chain: z.object({
357
- bitcoin: z.object({
358
- blockchain: z.literal("bitcoin"),
359
- bitcoinUrl: z.string(),
434
+ import { z as z4 } from "zod";
435
+ var bitcoinNetworkModesSchema = z4.enum([...networkModes, ...testnetModes]);
436
+ var bitcoinNetworkSchema = z4.enum([...bitcoinNetworks]);
437
+ var networkConfigurationSchema = z4.object({
438
+ name: z4.string(),
439
+ id: z4.string(),
440
+ chain: z4.object({
441
+ bitcoin: z4.object({
442
+ blockchain: z4.literal("bitcoin"),
443
+ bitcoinUrl: z4.string(),
360
444
  bitcoinNetwork: bitcoinNetworkSchema,
361
445
  mode: bitcoinNetworkModesSchema
362
446
  }),
363
- stacks: z.object({
364
- blockchain: z.literal("stacks"),
365
- url: z.string(),
366
- chainId: z.number(),
367
- subnetChainId: z.number().optional()
447
+ stacks: z4.object({
448
+ blockchain: z4.literal("stacks"),
449
+ url: z4.string(),
450
+ chainId: z4.number(),
451
+ subnetChainId: z4.number().optional()
368
452
  })
369
453
  })
370
454
  });
371
455
 
372
456
  // src/settings.model.ts
373
- import { z as z2 } from "zod";
374
- var emailAddressSchema = z2.email({ error: "Invalid email address" });
457
+ import { z as z5 } from "zod";
458
+ var accountDisplayPreferenceSchema = z5.enum(["native-segwit", "taproot", "bns", "stacks"]);
459
+ var analyticsPreferenceSchema = z5.enum(["consent-given", "rejects-tracking"]);
460
+ var emailAddressSchema = z5.email({ error: "Invalid email address" });
375
461
 
376
- // src/activity/activity-level.model.ts
377
- var ActivityLevels = {
378
- account: "account",
379
- app: "app"
380
- };
462
+ // src/swap/swap.model.ts
463
+ var swapProviderIds = ["bitflow-sdk", "sbtc-bridge", "alex-sdk", "velar-sdk"];
464
+ var swapExecutionTypes = ["stacks-contract-call", "sbtc-bridge-transfer"];
381
465
 
382
- // src/activity/activity-status.model.ts
383
- var OnChainActivityStatuses = {
384
- pending: "pending",
385
- success: "success",
386
- failed: "failed"
466
+ // src/yield/yield-provider.model.ts
467
+ var YieldProviderKeys = {
468
+ bitflow: "bitflow",
469
+ zest: "zest",
470
+ granite: "granite",
471
+ stackingDao: "stackingdao"
472
+ // fastPool: 'fast-pool',
473
+ // xverse: 'xverse',
387
474
  };
388
475
 
389
- // src/activity/activity-type.model.ts
390
- var OnChainActivityTypes = {
391
- deploySmartContract: "deploySmartContract",
392
- executeSmartContract: "executeSmartContract",
393
- lockAsset: "lockAsset",
394
- sendAsset: "sendAsset",
395
- receiveAsset: "receiveAsset",
396
- swapAssets: "swapAssets"
476
+ // src/yield/yield-product.model.ts
477
+ var YieldProductKeys = {
478
+ bitflowAmmLp: "bitflow-amm-lp",
479
+ zestBorrow: "zest-borrow",
480
+ graniteV1: "granite-v1",
481
+ stackingDaoLst: "stackingdao-lst",
482
+ stackingDaoPooledStacking: "stackingdao-pooled-stacking"
483
+ // fastPoolPooledStacking: 'fast-pool-pooled-stacking',
484
+ // xversePooledStacking: 'xverse-pooled-stacking',
397
485
  };
398
- var WalletActivityTypes = {
399
- connectApp: "connectApp",
400
- signMessage: "signMessage"
486
+ var YieldProductCategories = {
487
+ AMM: "amm",
488
+ LENDING: "lending",
489
+ LST: "lst",
490
+ CDP: "cdp",
491
+ POOLED_STACKING: "pooled-stacking",
492
+ PERPS: "perps"
401
493
  };
402
- var GeneralActivityTypes = {
403
- walletAdded: "walletAdded",
404
- receiveAnnouncement: "receiveAnnouncement",
405
- featureWaitlistNotification: "featureWaitlistNotification"
494
+ var YieldProductToProtocolMap = {
495
+ [YieldProductKeys.bitflowAmmLp]: YieldProviderKeys.bitflow,
496
+ [YieldProductKeys.zestBorrow]: YieldProviderKeys.zest,
497
+ [YieldProductKeys.graniteV1]: YieldProviderKeys.granite,
498
+ [YieldProductKeys.stackingDaoLst]: YieldProviderKeys.stackingDao,
499
+ [YieldProductKeys.stackingDaoPooledStacking]: YieldProviderKeys.stackingDao
500
+ // [YieldProductKeys.fastPoolPooledStacking]: YieldProviderKeys.fastPool,
501
+ // [YieldProductKeys.xversePooledStacking]: YieldProviderKeys.xverse,
406
502
  };
407
503
 
408
- // src/account.model.ts
409
- import { z as z3 } from "zod";
410
- var walletIdSchema = z3.object({
411
- fingerprint: z3.string()
412
- });
413
- var accountIdSchema = walletIdSchema.and(z3.object({ accountIndex: z3.number() }));
414
- var bitcoinAddressInfoSchema = z3.object({
415
- taprootDescriptor: z3.string(),
416
- nativeSegwitDescriptor: z3.string(),
417
- zeroIndexTaprootPayerAddress: z3.string().optional(),
418
- zeroIndexNativeSegwitPayerAddress: z3.string().optional()
419
- });
420
- var stacksAddressInfoSchema = z3.object({
421
- stxAddress: z3.string()
422
- });
423
- var accountAddressesSchema = z3.object({
424
- id: accountIdSchema,
425
- bitcoin: bitcoinAddressInfoSchema.optional(),
426
- stacks: stacksAddressInfoSchema.optional()
427
- });
428
-
429
- // src/bns.model.ts
430
- var bnsContractAddress = {
431
- mainnet: "SP2QEZ06AGJ3RKJPBV14SY1V5BBFNAW33D96YPGZF",
432
- testnet: "ST2QEZ06AGJ3RKJPBV14SY1V5BBFNAW33D9SZJQ0M"
433
- };
434
- var bnsContractName = "BNS-V2";
435
-
436
- // src/swap/swap.model.ts
437
- var swapProviderIds = ["bitflow-sdk", "sbtc-bridge", "alex-sdk", "velar-sdk"];
438
- var swapExecutionTypes = ["stacks-contract-call", "sbtc-bridge-transfer"];
504
+ // src/yield/helpers/yield.helpers.ts
505
+ function isBitflowPosition(pos) {
506
+ return pos.product === YieldProductKeys.bitflowAmmLp;
507
+ }
508
+ function isZestPosition(pos) {
509
+ return pos.product === YieldProductKeys.zestBorrow;
510
+ }
511
+ function isGranitePosition(pos) {
512
+ return pos.product === YieldProductKeys.graniteV1;
513
+ }
514
+ function isStackingDaoLstPosition(pos) {
515
+ return pos.product === YieldProductKeys.stackingDaoLst;
516
+ }
517
+ function isStackingDaoPooledPosition(pos) {
518
+ return pos.product === YieldProductKeys.stackingDaoPooledStacking;
519
+ }
520
+ function filterPositionsByProtocol(positions, protocol) {
521
+ return positions.filter((p) => p.provider === protocol);
522
+ }
523
+ function filterPositionsByProduct(positions, product) {
524
+ return positions.filter((p) => p.product === product);
525
+ }
526
+ function filterPositionsByCategory(positions, products, category) {
527
+ const productMap = new Map(products.map((p) => [p.key, p]));
528
+ return positions.filter((pos) => productMap.get(pos.product)?.category === category);
529
+ }
530
+ function sortPositionsByBalance(positions, ascending = false) {
531
+ return [...positions].sort((a, b) => {
532
+ const diff = a.totalBalance.amount.comparedTo(b.totalBalance.amount);
533
+ return ascending ? diff : -diff;
534
+ });
535
+ }
536
+ function sortPositionsByApy(positions, ascending = false) {
537
+ return [...positions].sort((a, b) => {
538
+ const apyA = a.netApy ?? 0;
539
+ const apyB = b.netApy ?? 0;
540
+ return ascending ? apyA - apyB : apyB - apyA;
541
+ });
542
+ }
543
+ function sortPositionsByUpdateTime(positions, ascending = false) {
544
+ return [...positions].sort((a, b) => {
545
+ const timeA = a.updatedAt?.getTime() ?? 0;
546
+ const timeB = b.updatedAt?.getTime() ?? 0;
547
+ return ascending ? timeA - timeB : timeB - timeA;
548
+ });
549
+ }
550
+ function getProtocolForProduct(product) {
551
+ return YieldProductToProtocolMap[product];
552
+ }
553
+ function getCategoryForProduct(product) {
554
+ return product.category;
555
+ }
556
+ function isProductInProtocol(product, protocol) {
557
+ return YieldProductToProtocolMap[product] === protocol;
558
+ }
559
+ function getProductsForProtocol(protocol) {
560
+ return Object.entries(YieldProductToProtocolMap).filter(([_, p]) => p === protocol).map(([product]) => product);
561
+ }
562
+ function getProductsInCategory(products, category) {
563
+ return products.filter((p) => p.category === category);
564
+ }
565
+ function groupPositionsByProtocol(positions) {
566
+ const grouped = {};
567
+ for (const position of positions) {
568
+ const protocol = position.provider;
569
+ if (!grouped[protocol]) {
570
+ grouped[protocol] = [];
571
+ }
572
+ grouped[protocol].push(position);
573
+ }
574
+ return grouped;
575
+ }
576
+ function groupPositionsByCategory(positions, products) {
577
+ const grouped = {};
578
+ const productMap = new Map(products.map((p) => [p.key, p]));
579
+ for (const position of positions) {
580
+ const product = productMap.get(position.product);
581
+ if (!product) continue;
582
+ const category = product.category;
583
+ if (!grouped[category]) {
584
+ grouped[category] = [];
585
+ }
586
+ grouped[category].push(position);
587
+ }
588
+ return grouped;
589
+ }
590
+ function getPositionsInCategories(positions, products, categories) {
591
+ const categorySet = new Set(categories);
592
+ const productMap = new Map(products.map((p) => [p.key, p]));
593
+ return positions.filter((pos) => {
594
+ const product = productMap.get(pos.product);
595
+ return product && categorySet.has(product.category);
596
+ });
597
+ }
598
+ function hasPositionsInProtocol(positions, protocol) {
599
+ return positions.some((p) => p.provider === protocol);
600
+ }
601
+ function hasPositionsInCategory(positions, products, category) {
602
+ const productMap = new Map(products.map((p) => [p.key, p]));
603
+ return positions.some((pos) => productMap.get(pos.product)?.category === category);
604
+ }
605
+ function enrichPositionWithProtocol(position, protocol) {
606
+ return { ...position, protocolData: protocol };
607
+ }
608
+ function enrichPositionWithProduct(position, product) {
609
+ return { ...position, productData: product };
610
+ }
611
+ function enrichPositionWithMetadata(position, protocol, product) {
612
+ return { ...position, protocolData: protocol, productData: product };
613
+ }
614
+ function getCategoryDisplayName(category) {
615
+ const displayNames = {
616
+ [YieldProductCategories.AMM]: "Liquidity Pools",
617
+ [YieldProductCategories.LENDING]: "Lending & Borrowing",
618
+ [YieldProductCategories.LST]: "Liquid Stacking",
619
+ [YieldProductCategories.CDP]: "Collateralized Debt",
620
+ [YieldProductCategories.POOLED_STACKING]: "Stacking",
621
+ [YieldProductCategories.PERPS]: "Perpetuals"
622
+ };
623
+ return displayNames[category] || category;
624
+ }
439
625
  export {
440
626
  ActivityLevels,
441
627
  BESTINSLOT_API_BASE_URL_MAINNET,
@@ -465,45 +651,81 @@ export {
465
651
  STX20_API_BASE_URL_MAINNET,
466
652
  WalletActivityTypes,
467
653
  WalletDefaultNetworkConfigurationIds,
654
+ YieldProductCategories,
655
+ YieldProductKeys,
656
+ YieldProductToProtocolMap,
657
+ YieldProviderKeys,
468
658
  accountAddressesSchema,
659
+ accountDisplayPreferenceSchema,
469
660
  accountIdSchema,
661
+ analyticsPreferenceSchema,
470
662
  bitcoinAddressInfoSchema,
471
663
  bitcoinNetworkModesSchema,
472
664
  bitcoinNetworkSchema,
473
665
  bitcoinNetworkToNetworkMode,
474
666
  bitcoinNetworks,
667
+ bitcoinUnitSchema,
475
668
  bnsContractAddress,
476
669
  bnsContractName,
477
670
  btcTxTimeMap,
478
671
  createMarketData,
479
672
  createMarketPair,
480
673
  defaultCurrentNetwork,
674
+ defaultNetworkConfigurationsSchema,
481
675
  defaultNetworksKeyedById,
482
676
  emailAddressSchema,
677
+ enrichPositionWithMetadata,
678
+ enrichPositionWithProduct,
679
+ enrichPositionWithProtocol,
680
+ filterPositionsByCategory,
681
+ filterPositionsByProduct,
682
+ filterPositionsByProtocol,
483
683
  formatMarketPair,
684
+ getCategoryDisplayName,
685
+ getCategoryForProduct,
686
+ getPositionsInCategories,
687
+ getProductsForProtocol,
688
+ getProductsInCategory,
689
+ getProtocolForProduct,
690
+ groupPositionsByCategory,
691
+ groupPositionsByProtocol,
692
+ hasPositionsInCategory,
693
+ hasPositionsInProtocol,
694
+ historicalPeriods,
484
695
  inscriptionMimeTypes,
696
+ isBitflowPosition,
485
697
  isBrc20Asset,
486
698
  isBtcAsset,
487
699
  isFungibleAsset,
700
+ isGranitePosition,
488
701
  isInscriptionAsset,
489
702
  isNativeAsset,
490
703
  isNonFungibleAsset,
704
+ isProductInProtocol,
491
705
  isRuneAsset,
492
706
  isSip10Asset,
493
707
  isSip9Asset,
494
708
  isSrc20Asset,
709
+ isStackingDaoLstPosition,
710
+ isStackingDaoPooledPosition,
495
711
  isStampAsset,
496
712
  isStx20Asset,
497
713
  isStxAsset,
498
714
  isSwappableAsset,
715
+ isZestPosition,
499
716
  networkConfigurationSchema,
500
717
  networkModes,
501
718
  sip9ContentTypes,
719
+ sortPositionsByApy,
720
+ sortPositionsByBalance,
721
+ sortPositionsByUpdateTime,
502
722
  stacksAddressInfoSchema,
503
723
  supportedBlockchains,
504
724
  swapExecutionTypes,
505
725
  swapProviderIds,
506
726
  testnetModes,
727
+ transactionFeeQuoteType,
728
+ transactionFeeTiers,
507
729
  walletIdSchema
508
730
  };
509
731
  //# sourceMappingURL=index.js.map