@keplr-wallet/stores 0.12.300-rc.0 → 0.12.304

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.
Files changed (103) hide show
  1. package/build/account/babylon.js +7 -19
  2. package/build/account/babylon.js.map +1 -1
  3. package/build/account/base.js +5 -7
  4. package/build/account/base.js.map +1 -1
  5. package/build/account/cosmos.js +54 -94
  6. package/build/account/cosmos.js.map +1 -1
  7. package/build/account/cosmwasm.js +2 -10
  8. package/build/account/cosmwasm.js.map +1 -1
  9. package/build/account/secret.js +2 -10
  10. package/build/account/secret.js.map +1 -1
  11. package/build/account/store.js +4 -4
  12. package/build/account/store.js.map +1 -1
  13. package/build/chain/base.d.ts +1 -122
  14. package/build/chain/base.js +40 -601
  15. package/build/chain/base.js.map +1 -1
  16. package/build/chain/types.d.ts +1 -27
  17. package/build/common/utils/index.d.ts +2 -2
  18. package/build/common/utils/index.js.map +1 -1
  19. package/build/lsm/currency-registrar.js +7 -7
  20. package/build/lsm/currency-registrar.js.map +1 -1
  21. package/build/query/balances.js +11 -24
  22. package/build/query/balances.js.map +1 -1
  23. package/build/query/chain-query.js +2 -2
  24. package/build/query/chain-query.js.map +1 -1
  25. package/build/query/chain-rpc-query.js +2 -2
  26. package/build/query/chain-rpc-query.js.map +1 -1
  27. package/build/query/cosmos/balance/balances.js +4 -8
  28. package/build/query/cosmos/balance/balances.js.map +1 -1
  29. package/build/query/cosmos/balance/spendable.js +2 -3
  30. package/build/query/cosmos/balance/spendable.js.map +1 -1
  31. package/build/query/cosmos/ibc/channel.js +2 -3
  32. package/build/query/cosmos/ibc/channel.js.map +1 -1
  33. package/build/query/cosmos/ibc/client-state.js +2 -2
  34. package/build/query/cosmos/ibc/client-state.js.map +1 -1
  35. package/build/query/cosmos/ibc/denom-trace.js +8 -6
  36. package/build/query/cosmos/ibc/denom-trace.js.map +1 -1
  37. package/build/query/cosmos/staking/babylon-btc-delegation-reward.js +2 -3
  38. package/build/query/cosmos/staking/babylon-btc-delegation-reward.js.map +1 -1
  39. package/build/query/cosmos/staking/delegations.js +4 -5
  40. package/build/query/cosmos/staking/delegations.js.map +1 -1
  41. package/build/query/cosmos/staking/initia-delegations.js +6 -8
  42. package/build/query/cosmos/staking/initia-delegations.js.map +1 -1
  43. package/build/query/cosmos/staking/initia-unbonding-delegations.js +5 -6
  44. package/build/query/cosmos/staking/initia-unbonding-delegations.js.map +1 -1
  45. package/build/query/cosmos/staking/initia-validators.js +3 -3
  46. package/build/query/cosmos/staking/initia-validators.js.map +1 -1
  47. package/build/query/cosmos/staking/pool.js +3 -3
  48. package/build/query/cosmos/staking/pool.js.map +1 -1
  49. package/build/query/cosmos/staking/rewards.js +10 -13
  50. package/build/query/cosmos/staking/rewards.js.map +1 -1
  51. package/build/query/cosmos/staking/unbonding-delegations.js +3 -3
  52. package/build/query/cosmos/staking/unbonding-delegations.js.map +1 -1
  53. package/build/query/cosmos/staking/validators.js +3 -2
  54. package/build/query/cosmos/staking/validators.js.map +1 -1
  55. package/build/query/cosmwasm/contract-query.js +2 -2
  56. package/build/query/cosmwasm/contract-query.js.map +1 -1
  57. package/build/query/cosmwasm/cw20-balance.js +4 -7
  58. package/build/query/cosmwasm/cw20-balance.js.map +1 -1
  59. package/build/query/cosmwasm/neutron/staking-rewards.js +8 -10
  60. package/build/query/cosmwasm/neutron/staking-rewards.js.map +1 -1
  61. package/build/query/noble/swap/simulate-swap.js +1 -1
  62. package/build/query/noble/swap/simulate-swap.js.map +1 -1
  63. package/build/query/osmosis/txfees/fee-tokens/index.js +4 -8
  64. package/build/query/osmosis/txfees/fee-tokens/index.js.map +1 -1
  65. package/build/query/secret-wasm/secret20-balance.js +5 -7
  66. package/build/query/secret-wasm/secret20-balance.js.map +1 -1
  67. package/build/token-factory/currency-registrar.js +1 -1
  68. package/build/token-factory/currency-registrar.js.map +1 -1
  69. package/package.json +15 -11
  70. package/src/account/babylon.ts +7 -21
  71. package/src/account/base.ts +5 -7
  72. package/src/account/cosmos.ts +66 -121
  73. package/src/account/cosmwasm.ts +3 -12
  74. package/src/account/secret.ts +3 -12
  75. package/src/account/store.ts +4 -4
  76. package/src/chain/base.ts +34 -816
  77. package/src/chain/types.ts +1 -27
  78. package/src/common/utils/index.ts +2 -2
  79. package/src/lsm/currency-registrar.ts +7 -9
  80. package/src/query/balances.ts +13 -30
  81. package/src/query/chain-query.ts +2 -6
  82. package/src/query/chain-rpc-query.ts +2 -6
  83. package/src/query/cosmos/balance/balances.ts +4 -8
  84. package/src/query/cosmos/balance/spendable.ts +3 -3
  85. package/src/query/cosmos/ibc/channel.ts +2 -5
  86. package/src/query/cosmos/ibc/client-state.ts +2 -2
  87. package/src/query/cosmos/ibc/denom-trace.ts +7 -7
  88. package/src/query/cosmos/staking/babylon-btc-delegation-reward.ts +2 -5
  89. package/src/query/cosmos/staking/delegations.ts +4 -9
  90. package/src/query/cosmos/staking/initia-delegations.ts +7 -14
  91. package/src/query/cosmos/staking/initia-unbonding-delegations.ts +6 -12
  92. package/src/query/cosmos/staking/initia-validators.ts +3 -5
  93. package/src/query/cosmos/staking/pool.ts +3 -3
  94. package/src/query/cosmos/staking/rewards.ts +10 -13
  95. package/src/query/cosmos/staking/unbonding-delegations.ts +3 -7
  96. package/src/query/cosmos/staking/validators.ts +3 -4
  97. package/src/query/cosmwasm/contract-query.ts +2 -4
  98. package/src/query/cosmwasm/cw20-balance.ts +5 -8
  99. package/src/query/cosmwasm/neutron/staking-rewards.ts +8 -10
  100. package/src/query/noble/swap/simulate-swap.ts +1 -1
  101. package/src/query/osmosis/txfees/fee-tokens/index.ts +4 -8
  102. package/src/query/secret-wasm/secret20-balance.ts +5 -7
  103. package/src/token-factory/currency-registrar.ts +1 -1
@@ -455,76 +455,27 @@ __decorate([
455
455
  ], ChainInfoImpl.prototype, "setEmbeddedChainInfo", null);
456
456
  exports.ChainInfoImpl = ChainInfoImpl;
457
457
  class ModularChainInfoImpl {
458
- get unknownDenomMap() {
459
- return new Map();
460
- }
461
458
  constructor(embedded, currencyRegistry) {
462
459
  this.currencyRegistry = currencyRegistry;
463
460
  this.registeredCosmosCurrencies = [];
464
461
  this.registeredStarkentCurrencies = [];
465
462
  this.registeredBitcoinCurrencies = [];
466
- this.registeredEvmCurrencies = [];
467
- this.registeredCurrenciesNoReaction = [];
468
- this.registrationInProgressCurrencyMap = new Map();
469
463
  this._embedded = embedded;
470
- this.availableModules = this.detectAvailableModules();
471
464
  (0, mobx_1.makeObservable)(this);
472
465
  (0, mobx_utils_1.keepAlive)(this, "cosmosCurrencyMap");
473
466
  (0, mobx_utils_1.keepAlive)(this, "starknetCurrencyMap");
474
467
  (0, mobx_utils_1.keepAlive)(this, "bitcoinCurrencyMap");
475
- (0, mobx_utils_1.keepAlive)(this, "evmCurrencyMap");
476
- }
477
- detectAvailableModules() {
478
- const modules = [];
479
- if ("bitcoin" in this._embedded)
480
- modules.push("bitcoin");
481
- if ("starknet" in this._embedded)
482
- modules.push("starknet");
483
- if ("evm" in this._embedded)
484
- modules.push("evm");
485
- if ("cosmos" in this._embedded)
486
- modules.push("cosmos");
487
- return modules;
488
468
  }
489
469
  get embedded() {
490
470
  return this._embedded;
491
471
  }
492
472
  setEmbeddedModularChainInfo(embedded) {
493
473
  this._embedded = embedded;
494
- this.availableModules = this.detectAvailableModules();
495
474
  }
496
475
  get chainId() {
497
476
  return this._embedded.chainId;
498
477
  }
499
- get stakeCurrency() {
500
- return "cosmos" in this._embedded
501
- ? this._embedded.cosmos.stakeCurrency
502
- : undefined;
503
- }
504
- get feeCurrencies() {
505
- if ("cosmos" in this._embedded) {
506
- return this._embedded.cosmos.feeCurrencies;
507
- }
508
- if ("evm" in this._embedded) {
509
- return this._embedded.evm.feeCurrencies;
510
- }
511
- if ("starknet" in this._embedded) {
512
- const feeContractAddress = this._embedded.starknet.strkContractAddress;
513
- const feeCurrency = this.getCurrenciesByModule("starknet").find((cur) => cur.coinMinimalDenom === `erc20:${feeContractAddress}`);
514
- if (feeCurrency) {
515
- return [feeCurrency];
516
- }
517
- }
518
- if ("bitcoin" in this._embedded) {
519
- return [this._embedded.bitcoin.currencies[0]];
520
- }
521
- }
522
- getCurrencies() {
523
- return this.availableModules
524
- .map((module) => this.getCurrenciesByModule(module))
525
- .flat();
526
- }
527
- getCurrenciesByModule(module) {
478
+ getCurrencies(module) {
528
479
  switch (module) {
529
480
  case "cosmos":
530
481
  if (!("cosmos" in this._embedded)) {
@@ -541,407 +492,6 @@ class ModularChainInfoImpl {
541
492
  throw new Error(`No bitcoin module for this chain: ${this.chainId}`);
542
493
  }
543
494
  return this._embedded.bitcoin.currencies.concat(this.registeredBitcoinCurrencies);
544
- case "evm":
545
- if (!("evm" in this._embedded)) {
546
- throw new Error(`No evm native module for this chain: ${this.chainId}`);
547
- }
548
- return this._embedded.evm.currencies.concat(this.registeredEvmCurrencies);
549
- default:
550
- throw new Error(`Unknown module: ${module}`);
551
- }
552
- }
553
- /**
554
- * Currency를 반환한다.
555
- * 만약 해당 Currency가 없다면 unknownDenomMap에 추가한다.
556
- * @param coinMinimalDenom
557
- */
558
- findCurrency(coinMinimalDenom) {
559
- const normalizedDenom = common_1.DenomHelper.normalizeDenom(coinMinimalDenom);
560
- const currency = this.findCurrencyByModule(normalizedDenom);
561
- if (currency) {
562
- return currency;
563
- }
564
- this.availableModules.forEach((module) => {
565
- // 동적으로 토큰을 발견하고 등록하는 절차는 cosmos, evm 모듈에서만 지원
566
- if (module === "cosmos" || module === "evm") {
567
- this.addUnknownDenomsImpl({
568
- module,
569
- coinMinimalDenoms: [normalizedDenom],
570
- reaction: true,
571
- });
572
- }
573
- });
574
- // Unknown denom can be registered synchronously in some cases.
575
- // For this case, re-try to get currency.
576
- return this.findCurrencyByModule(normalizedDenom);
577
- }
578
- findCurrencyByModule(denom) {
579
- for (const module of this.availableModules) {
580
- const currency = this.getCurrencyMapByModule(module).get(denom);
581
- if (currency) {
582
- return currency;
583
- }
584
- if (module === "cosmos" || module === "evm") {
585
- const noReactionCurrency = this.currencyMapNoReaction.get(denom);
586
- if (noReactionCurrency) {
587
- return noReactionCurrency;
588
- }
589
- }
590
- }
591
- return undefined;
592
- }
593
- /**
594
- * findCurrency와 비슷하지만 해당하는 currency가 존재하지 않을 경우 raw currency를 반환한다.
595
- * @param coinMinimalDenom
596
- */
597
- forceFindCurrency(coinMinimalDenom) {
598
- const normalizedCoinMinimalDenom = common_1.DenomHelper.normalizeDenom(coinMinimalDenom);
599
- const currency = this.findCurrency(coinMinimalDenom);
600
- if (currency) {
601
- return currency;
602
- }
603
- return this.getRawCurrency(normalizedCoinMinimalDenom);
604
- }
605
- /**
606
- * 최적화를 위해 reaction 없이 currency를 조회한다.
607
- * 현재는 IBC asset에서만 사용되고 있어 Cosmos 모듈만 지원한다.
608
- * @param coinMinimalDenom
609
- */
610
- findCurrencyWithoutReaction(coinMinimalDenom) {
611
- const normalizedCoinMinimalDenom = common_1.DenomHelper.normalizeDenom(coinMinimalDenom);
612
- const currency = this.findCurrencyByModule(normalizedCoinMinimalDenom);
613
- if (currency) {
614
- return currency;
615
- }
616
- this.availableModules.forEach((module) => {
617
- if (module === "cosmos" || module === "evm") {
618
- this.addUnknownDenomsImpl({
619
- module,
620
- coinMinimalDenoms: [normalizedCoinMinimalDenom],
621
- reaction: false,
622
- });
623
- }
624
- });
625
- // Unknown denom can be registered synchronously in some cases.
626
- // For this case, re-try to get currency.
627
- return this.findCurrencyByModule(normalizedCoinMinimalDenom);
628
- }
629
- findCurrencyAsync(coinMinimalDenom) {
630
- const normalizedCoinMinimalDenom = common_1.DenomHelper.normalizeDenom(coinMinimalDenom);
631
- const currency = this.findCurrencyByModule(normalizedCoinMinimalDenom);
632
- if (currency) {
633
- return Promise.resolve(currency);
634
- }
635
- this.availableModules.forEach((module) => {
636
- if (module === "cosmos" || module === "evm") {
637
- this.addUnknownDenomsImpl({
638
- module,
639
- coinMinimalDenoms: [normalizedCoinMinimalDenom],
640
- reaction: true,
641
- });
642
- }
643
- });
644
- let disposal;
645
- return new Promise((resolve) => {
646
- disposal = (0, mobx_1.autorun)(() => {
647
- const registration = this.registrationInProgressCurrencyMap.get(normalizedCoinMinimalDenom);
648
- if (!registration) {
649
- const result = this.findCurrencyByModule(normalizedCoinMinimalDenom);
650
- resolve(result);
651
- }
652
- });
653
- }).finally(() => {
654
- if (disposal) {
655
- disposal();
656
- }
657
- });
658
- }
659
- forceFindCurrencyWithoutReaction(coinMinimalDenom) {
660
- const normalizedCoinMinimalDenom = common_1.DenomHelper.normalizeDenom(coinMinimalDenom);
661
- const currency = this.findCurrencyWithoutReaction(normalizedCoinMinimalDenom);
662
- if (currency) {
663
- return currency;
664
- }
665
- return this.getRawCurrency(normalizedCoinMinimalDenom);
666
- }
667
- /**
668
- * raw currency를 반환한다. ref을 유지하기 위해서 cache를 사용한다.
669
- */
670
- getRawCurrency(denom) {
671
- if (forceFindCurrencyCache.has(denom)) {
672
- return forceFindCurrencyCache.get(denom);
673
- }
674
- const currency = {
675
- coinMinimalDenom: denom,
676
- coinDenom: denom,
677
- coinDecimals: 0,
678
- };
679
- forceFindCurrencyCache.set(denom, currency);
680
- return currency;
681
- }
682
- addUnknownDenoms({ module, coinMinimalDenoms, }) {
683
- this.addUnknownDenomsImpl({
684
- module,
685
- coinMinimalDenoms,
686
- reaction: true,
687
- });
688
- }
689
- addUnknownDenomsWithoutReaction({ module, coinMinimalDenoms, }) {
690
- this.addUnknownDenomsImpl({
691
- module,
692
- coinMinimalDenoms,
693
- reaction: false,
694
- });
695
- }
696
- /**
697
- * 해당되는 denom의 currency를 모를 때 이 메소드를 사용해서 등록을 요청할 수 있다.
698
- *
699
- * - balance 쿼리 결과 등에서 모르는 denom이 나타날 때
700
- * - IBC denom을 동적으로 등록해야 할 때
701
- * ---
702
- * - action 데코레이터가 사용되지 않은 이유: action 내부에서 autorun을 생성하면, autorun의 첫 실행이 action이 끝날 때까지 지연된다.
703
- * autorun을 사용하는 startCurrencyRegistration 내부에서 불필요한 지연이 발생할 수 있어 action 없이 구현하여 autorun을 즉시 실행한다.
704
- * 하지만 이 메소드를 action 안에서 호출하게 되는 경우가 있다면 여전히 즉시 실행되지 않으므로 고려가 필요하다.
705
- */
706
- addUnknownDenomsImpl({ module, coinMinimalDenoms, reaction, }) {
707
- for (const coinMinimalDenom of coinMinimalDenoms) {
708
- const normalizedDenom = common_1.DenomHelper.normalizeDenom(coinMinimalDenom);
709
- // 이미 등록 중인 경우 reaction 모드만 업데이트하고 스킵
710
- if (this.shouldSkipUnknownDenom(normalizedDenom, reaction)) {
711
- continue;
712
- }
713
- // 이미 currency가 존재하면 스킵
714
- if (reaction &&
715
- this.getCurrencyMapByModule(module).has(normalizedDenom)) {
716
- continue;
717
- }
718
- // noreaction 맵 확인
719
- if (!reaction && this.currencyMapNoReaction.has(normalizedDenom)) {
720
- continue;
721
- }
722
- // unknownDenomMap에 등록 및 등록진행중 상태로 변경
723
- const isNewUnknownDenom = this.addToUnknownDenomMapAndReturnIsNew(normalizedDenom, reaction);
724
- // 새로운 unknown denom인 경우에만 autorun 시작
725
- if (isNewUnknownDenom) {
726
- this.startCurrencyRegistration(module, normalizedDenom);
727
- }
728
- }
729
- }
730
- // module별 currency map 제공
731
- getCurrencyMapByModule(module) {
732
- switch (module) {
733
- case "cosmos":
734
- return this.cosmosCurrencyMap;
735
- case "starknet":
736
- return this.starknetCurrencyMap;
737
- case "bitcoin":
738
- return this.bitcoinCurrencyMap;
739
- case "evm":
740
- return this.evmCurrencyMap;
741
- default:
742
- throw new Error(`Unknown module: ${module}`);
743
- }
744
- }
745
- /**
746
- * 이미 등록 중인 unknown denom인지 체크하고, reaction 업데이트
747
- */
748
- shouldSkipUnknownDenom(normalizedDenom, reaction) {
749
- const prior = this.unknownDenomMap.get(normalizedDenom);
750
- if (!prior) {
751
- return false;
752
- }
753
- // 같은 reaction 모드면 스킵
754
- if (prior.reaction === reaction) {
755
- return true;
756
- }
757
- // noReaction을 reaction으로 변경하는 경우
758
- if (reaction) {
759
- // 로직상 reaction은 reactive할 필요가 없기 때문에 직접 변경
760
- prior.reaction = reaction;
761
- }
762
- return true;
763
- }
764
- /**
765
- * unknownDenomMap에 등록 및 등록진행중 상태로 변경
766
- * @returns 새로 추가된 경우 true, 이미 있던 경우 false
767
- */
768
- addToUnknownDenomMapAndReturnIsNew(denom, reaction) {
769
- const prior = this.unknownDenomMap.get(denom);
770
- if (prior) {
771
- return false; // 이미 존재하면 새로 추가하지 않음
772
- }
773
- (0, mobx_1.runInAction)(() => {
774
- this.unknownDenomMap.set(denom, {
775
- denom: denom,
776
- reaction,
777
- });
778
- this.registrationInProgressCurrencyMap.set(denom, true);
779
- });
780
- return true;
781
- }
782
- startCurrencyRegistration(module, denom) {
783
- let i = 0;
784
- let disposed = false;
785
- const disposer = (0, mobx_1.autorun)(() => {
786
- i++;
787
- // autorun의 첫 실행에서 즉시 dispose하면 disposer가 아직 undefined이므로
788
- // setTimeout으로 다음 회차로 안전하게 연기
789
- const dispose = () => {
790
- disposed = true;
791
- if (i === 1) {
792
- // 첫 실행: 다음 회차에 dispose
793
- setTimeout(() => {
794
- disposer === null || disposer === void 0 ? void 0 : disposer();
795
- }, 1);
796
- }
797
- else {
798
- // 두번째 이후: 즉시 dispose
799
- disposer === null || disposer === void 0 ? void 0 : disposer();
800
- }
801
- };
802
- // 이미 dispose된 경우 리턴
803
- if (disposed) {
804
- return;
805
- }
806
- const generator = this.currencyRegistry.getCurrencyRegistrar(this.chainId, denom);
807
- if (generator) {
808
- this.handleCurrencyRegistration({
809
- module,
810
- denom,
811
- generator,
812
- dispose,
813
- });
814
- }
815
- else {
816
- // registrar가 없으면 등록 불가능
817
- if (this.registrationInProgressCurrencyMap.get(denom)) {
818
- (0, mobx_1.runInAction)(() => {
819
- this.registrationInProgressCurrencyMap.delete(denom);
820
- });
821
- }
822
- dispose();
823
- }
824
- });
825
- }
826
- /**
827
- * currency 등록 진행
828
- */
829
- handleCurrencyRegistration(args) {
830
- const { module, denom, generator, dispose } = args;
831
- const currency = generator.value;
832
- (0, mobx_1.runInAction)(() => {
833
- // 진행 중 상태 업데이트
834
- if (!generator.done) {
835
- this.registrationInProgressCurrencyMap.set(denom, true);
836
- }
837
- // currency가 있으면 등록
838
- if (currency) {
839
- const unknownDenom = this.findAndRemoveUnknownDenom(denom, generator.done);
840
- // reaction 모드에 따라 적절한 메서드로 추가
841
- if (!unknownDenom || unknownDenom.reaction) {
842
- this.addOrReplaceCurrency(module, currency);
843
- }
844
- else {
845
- this.addOrReplaceCurrencyNoReaction(module, currency);
846
- }
847
- }
848
- // 완료되면 진행 중 상태 제거
849
- if (generator.done) {
850
- this.registrationInProgressCurrencyMap.delete(denom);
851
- }
852
- });
853
- // 완료되면 dispose
854
- if (generator.done) {
855
- dispose();
856
- }
857
- }
858
- /**
859
- * unknownDenomMap에서 해당 denom 찾고, 완료되었으면 제거
860
- * @returns 찾은 unknownDenom 정보 (없으면 undefined)
861
- */
862
- findAndRemoveUnknownDenom(denom, shouldRemove) {
863
- const unknownDenom = this.unknownDenomMap.get(denom);
864
- if (!unknownDenom) {
865
- return undefined;
866
- }
867
- if (shouldRemove) {
868
- this.unknownDenomMap.delete(denom);
869
- }
870
- return unknownDenom;
871
- }
872
- addOrReplaceCurrency(module, currency) {
873
- const currencyMap = this.getCurrencyMapByModule(module);
874
- const normalizedCoinMinimalDenom = common_1.DenomHelper.normalizeDenom(currency.coinMinimalDenom);
875
- const newRegisteredCurrencies = this.getRegisteredCurrencies(module).slice();
876
- if (currencyMap.has(normalizedCoinMinimalDenom)) {
877
- const index = newRegisteredCurrencies.findIndex((cur) => cur.coinMinimalDenom === normalizedCoinMinimalDenom);
878
- if (index >= 0) {
879
- const prev = newRegisteredCurrencies[index];
880
- if (
881
- // If same, do nothing
882
- (0, common_1.sortedJsonByKeyStringify)(prev) !== (0, common_1.sortedJsonByKeyStringify)(currency)) {
883
- newRegisteredCurrencies.splice(index, 1, currency);
884
- this.replaceRegisteredCurrencies(module, newRegisteredCurrencies);
885
- }
886
- }
887
- }
888
- else {
889
- newRegisteredCurrencies.push(currency);
890
- this.replaceRegisteredCurrencies(module, newRegisteredCurrencies);
891
- }
892
- }
893
- addOrReplaceCurrencyNoReaction(module, currency) {
894
- if (module !== "cosmos" && module !== "evm") {
895
- return;
896
- }
897
- const normalizedCoinMinimalDenom = common_1.DenomHelper.normalizeDenom(currency.coinMinimalDenom);
898
- const currencyMap = this.getCurrencyMapByModule(module);
899
- const newRegisteredCurrencies = this.registeredCurrenciesNoReaction.slice();
900
- if (currencyMap.has(normalizedCoinMinimalDenom)) {
901
- const index = newRegisteredCurrencies.findIndex((cur) => cur.coinMinimalDenom === normalizedCoinMinimalDenom);
902
- if (index >= 0) {
903
- const prev = newRegisteredCurrencies[index];
904
- if (
905
- // If same, do nothing
906
- (0, common_1.sortedJsonByKeyStringify)(prev) !== (0, common_1.sortedJsonByKeyStringify)(currency)) {
907
- newRegisteredCurrencies.splice(index, 1, currency);
908
- this.registeredCurrenciesNoReaction = newRegisteredCurrencies;
909
- }
910
- }
911
- }
912
- else {
913
- newRegisteredCurrencies.push(currency);
914
- this.registeredCurrenciesNoReaction = newRegisteredCurrencies;
915
- }
916
- }
917
- getRegisteredCurrencies(module) {
918
- switch (module) {
919
- case "cosmos":
920
- return this.registeredCosmosCurrencies;
921
- case "starknet":
922
- return this.registeredStarkentCurrencies;
923
- case "bitcoin":
924
- return this.registeredBitcoinCurrencies;
925
- case "evm":
926
- return this.registeredEvmCurrencies;
927
- default:
928
- throw new Error(`Unknown module: ${module}`);
929
- }
930
- }
931
- replaceRegisteredCurrencies(module, currencies) {
932
- switch (module) {
933
- case "cosmos":
934
- this.registeredCosmosCurrencies = currencies;
935
- break;
936
- case "starknet":
937
- this.registeredStarkentCurrencies = currencies;
938
- break;
939
- case "bitcoin":
940
- this.registeredBitcoinCurrencies = currencies;
941
- break;
942
- case "evm":
943
- this.registeredEvmCurrencies = currencies;
944
- break;
945
495
  default:
946
496
  throw new Error(`Unknown module: ${module}`);
947
497
  }
@@ -986,17 +536,6 @@ class ModularChainInfoImpl {
986
536
  }
987
537
  }
988
538
  break;
989
- case "evm":
990
- if (!("evm" in this._embedded)) {
991
- throw new Error(`No evm module for this chain: ${this.chainId}`);
992
- }
993
- for (const currency of currencies) {
994
- const normalizedCoinMinimalDenom = common_1.DenomHelper.normalizeDenom(currency.coinMinimalDenom);
995
- if (!this.evmCurrencyMap.has(normalizedCoinMinimalDenom)) {
996
- this.registeredEvmCurrencies.push(currency);
997
- }
998
- }
999
- break;
1000
539
  default:
1001
540
  throw new Error(`Unknown module: ${module}`);
1002
541
  }
@@ -1031,12 +570,6 @@ class ModularChainInfoImpl {
1031
570
  this.registeredBitcoinCurrencies =
1032
571
  this.registeredBitcoinCurrencies.filter((currency) => !map.get(currency.coinMinimalDenom));
1033
572
  break;
1034
- case "evm":
1035
- if (!("evm" in this._embedded)) {
1036
- throw new Error(`No evm module for this chain: ${this.chainId}`);
1037
- }
1038
- this.registeredEvmCurrencies = this.registeredEvmCurrencies.filter((currency) => !map.get(currency.coinMinimalDenom));
1039
- break;
1040
573
  default:
1041
574
  throw new Error(`Unknown module: ${module}`);
1042
575
  }
@@ -1048,16 +581,6 @@ class ModularChainInfoImpl {
1048
581
  result.set(currency.coinMinimalDenom, currency);
1049
582
  }
1050
583
  }
1051
- for (const currency of this.registeredCosmosCurrencies) {
1052
- result.set(common_1.DenomHelper.normalizeDenom(currency.coinMinimalDenom), currency);
1053
- }
1054
- return result;
1055
- }
1056
- get currencyMapNoReaction() {
1057
- const result = new Map();
1058
- for (const currency of this.registeredCurrenciesNoReaction) {
1059
- result.set(currency.coinMinimalDenom, currency);
1060
- }
1061
584
  return result;
1062
585
  }
1063
586
  get starknetCurrencyMap() {
@@ -1067,9 +590,6 @@ class ModularChainInfoImpl {
1067
590
  result.set(currency.coinMinimalDenom, currency);
1068
591
  }
1069
592
  }
1070
- for (const currency of this.registeredStarkentCurrencies) {
1071
- result.set(common_1.DenomHelper.normalizeDenom(currency.coinMinimalDenom), currency);
1072
- }
1073
593
  return result;
1074
594
  }
1075
595
  get bitcoinCurrencyMap() {
@@ -1079,51 +599,8 @@ class ModularChainInfoImpl {
1079
599
  result.set(currency.coinMinimalDenom, currency);
1080
600
  }
1081
601
  }
1082
- for (const currency of this.registeredBitcoinCurrencies) {
1083
- result.set(common_1.DenomHelper.normalizeDenom(currency.coinMinimalDenom), currency);
1084
- }
1085
602
  return result;
1086
603
  }
1087
- get evmCurrencyMap() {
1088
- const result = new Map();
1089
- if ("evm" in this._embedded) {
1090
- for (const currency of this._embedded.evm.currencies) {
1091
- result.set(common_1.DenomHelper.normalizeDenom(currency.coinMinimalDenom), currency);
1092
- }
1093
- }
1094
- for (const currency of this.registeredEvmCurrencies) {
1095
- result.set(common_1.DenomHelper.normalizeDenom(currency.coinMinimalDenom), currency);
1096
- }
1097
- return result;
1098
- }
1099
- hasFeature(feature) {
1100
- var _a, _b;
1101
- if ("evm" in this._embedded) {
1102
- return !!("features" in this._embedded.evm &&
1103
- ((_a = this._embedded.evm.features) === null || _a === void 0 ? void 0 : _a.includes(feature)));
1104
- }
1105
- if ("cosmos" in this._embedded) {
1106
- return !!("features" in this._embedded.cosmos &&
1107
- ((_b = this._embedded.cosmos.features) === null || _b === void 0 ? void 0 : _b.includes(feature)));
1108
- }
1109
- return false;
1110
- }
1111
- isCurrencyRegistrationInProgress(coinMinimalDenom) {
1112
- return (this.registrationInProgressCurrencyMap.get(coinMinimalDenom) || false);
1113
- }
1114
- /**
1115
- * @description Check if the chain matches the given modules. Either `or` or `and` condition must be provided.
1116
- * @param or - If any of the modules in the array is available, return true.
1117
- * @param and - If all of the modules in the array are available, return true.
1118
- */
1119
- matchModules({ and, or, }) {
1120
- var _a, _b;
1121
- return (((_a = or === null || or === void 0 ? void 0 : or.some((module) => this.matchModule(module))) !== null && _a !== void 0 ? _a : true) &&
1122
- ((_b = and === null || and === void 0 ? void 0 : and.every((module) => this.matchModule(module))) !== null && _b !== void 0 ? _b : true));
1123
- }
1124
- matchModule(module) {
1125
- return this.availableModules.includes(module);
1126
- }
1127
604
  }
1128
605
  __decorate([
1129
606
  mobx_1.observable.ref
@@ -1137,30 +614,9 @@ __decorate([
1137
614
  __decorate([
1138
615
  mobx_1.observable.shallow
1139
616
  ], ModularChainInfoImpl.prototype, "registeredBitcoinCurrencies", void 0);
1140
- __decorate([
1141
- mobx_1.observable.shallow
1142
- ], ModularChainInfoImpl.prototype, "registeredEvmCurrencies", void 0);
1143
- __decorate([
1144
- mobx_1.observable.shallow
1145
- ], ModularChainInfoImpl.prototype, "registeredCurrenciesNoReaction", void 0);
1146
- __decorate([
1147
- mobx_1.computed
1148
- ], ModularChainInfoImpl.prototype, "unknownDenomMap", null);
1149
- __decorate([
1150
- mobx_1.observable.shallow
1151
- ], ModularChainInfoImpl.prototype, "registrationInProgressCurrencyMap", void 0);
1152
- __decorate([
1153
- mobx_1.observable.shallow
1154
- ], ModularChainInfoImpl.prototype, "availableModules", void 0);
1155
617
  __decorate([
1156
618
  mobx_1.action
1157
619
  ], ModularChainInfoImpl.prototype, "setEmbeddedModularChainInfo", null);
1158
- __decorate([
1159
- mobx_1.action
1160
- ], ModularChainInfoImpl.prototype, "addOrReplaceCurrency", null);
1161
- __decorate([
1162
- mobx_1.action
1163
- ], ModularChainInfoImpl.prototype, "addOrReplaceCurrencyNoReaction", null);
1164
620
  __decorate([
1165
621
  mobx_1.action
1166
622
  ], ModularChainInfoImpl.prototype, "addCurrencies", null);
@@ -1170,18 +626,12 @@ __decorate([
1170
626
  __decorate([
1171
627
  mobx_1.computed
1172
628
  ], ModularChainInfoImpl.prototype, "cosmosCurrencyMap", null);
1173
- __decorate([
1174
- mobx_1.computed
1175
- ], ModularChainInfoImpl.prototype, "currencyMapNoReaction", null);
1176
629
  __decorate([
1177
630
  mobx_1.computed
1178
631
  ], ModularChainInfoImpl.prototype, "starknetCurrencyMap", null);
1179
632
  __decorate([
1180
633
  mobx_1.computed
1181
634
  ], ModularChainInfoImpl.prototype, "bitcoinCurrencyMap", null);
1182
- __decorate([
1183
- mobx_1.computed
1184
- ], ModularChainInfoImpl.prototype, "evmCurrencyMap", null);
1185
635
  exports.ModularChainInfoImpl = ModularChainInfoImpl;
1186
636
  class ChainStore {
1187
637
  constructor(embedChainInfos) {
@@ -1194,9 +644,6 @@ class ChainStore {
1194
644
  (0, mobx_utils_1.keepAlive)(this, "chainInfoMap");
1195
645
  (0, mobx_utils_1.keepAlive)(this, "modularChainInfoMap");
1196
646
  }
1197
- /**
1198
- * @deprecated Use `modularChainInfos` instead
1199
- */
1200
647
  get chainInfos() {
1201
648
  return this._chainInfos;
1202
649
  }
@@ -1213,9 +660,6 @@ class ChainStore {
1213
660
  }
1214
661
  return result;
1215
662
  }
1216
- /**
1217
- * @deprecated Use `getmodularChain` or `getModularChainInfoImpl` instead
1218
- */
1219
663
  getChain(chainId) {
1220
664
  const chainIdentifier = cosmos_1.ChainIdHelper.parse(chainId);
1221
665
  const chainInfo = this.chainInfoMap.get(chainIdentifier.identifier);
@@ -1224,9 +668,6 @@ class ChainStore {
1224
668
  }
1225
669
  return chainInfo;
1226
670
  }
1227
- /**
1228
- * @deprecated Use `hasModularChain` instead
1229
- */
1230
671
  hasChain(chainId) {
1231
672
  const chainIdentifier = cosmos_1.ChainIdHelper.parse(chainId);
1232
673
  return this.chainInfoMap.has(chainIdentifier.identifier);
@@ -1285,31 +726,25 @@ class ChainStore {
1285
726
  return new ChainInfoImpl(chainInfo, this);
1286
727
  });
1287
728
  this._modularChainInfos = chainInfos.map((chainInfo) => {
1288
- if ("evm" in chainInfo &&
1289
- chainInfo.evm &&
1290
- "currencies" in chainInfo && // clarify if it's ChainInfo type
1291
- this.isEvmOnlyChainForInit(chainInfo.chainId)) {
729
+ if ("currencies" in chainInfo) {
1292
730
  return {
1293
731
  chainId: chainInfo.chainId,
1294
732
  chainName: chainInfo.chainName,
1295
733
  chainSymbolImageUrl: chainInfo.chainSymbolImageUrl,
1296
- isTestnet: chainInfo.isTestnet,
1297
- isNative: true,
1298
- evm: Object.assign(Object.assign({}, chainInfo.evm), { currencies: chainInfo.currencies, feeCurrencies: chainInfo.feeCurrencies, bip44: chainInfo.bip44, features: chainInfo.features }),
734
+ cosmos: chainInfo,
1299
735
  };
1300
736
  }
1301
- if ("currencies" in chainInfo) {
1302
- return Object.assign({ chainId: chainInfo.chainId, chainName: chainInfo.chainName, chainSymbolImageUrl: chainInfo.chainSymbolImageUrl, isNative: true, cosmos: chainInfo }, (chainInfo.evm && {
1303
- evm: Object.assign(Object.assign({}, chainInfo.evm), { currencies: chainInfo.currencies, bip44: chainInfo.bip44 }),
1304
- }));
1305
- }
1306
- return Object.assign(Object.assign({}, chainInfo), { isNative: true });
737
+ return chainInfo;
1307
738
  });
1308
739
  this._modularChainInfoImpls = chainInfos.map((chainInfo) => {
1309
- const modularChainInfo = this._modularChainInfos.find((c) => c.chainId === chainInfo.chainId);
1310
- if (!modularChainInfo) {
1311
- throw new Error(`Unknown modular chain info: ${chainInfo.chainId}`);
1312
- }
740
+ const modularChainInfo = "currencies" in chainInfo
741
+ ? {
742
+ chainId: chainInfo.chainId,
743
+ chainName: chainInfo.chainName,
744
+ chainSymbolImageUrl: chainInfo.chainSymbolImageUrl,
745
+ cosmos: chainInfo,
746
+ }
747
+ : chainInfo;
1313
748
  const prev = this.modularChainInfoImplMap.get(cosmos_1.ChainIdHelper.parse(chainInfo.chainId).identifier);
1314
749
  if (prev) {
1315
750
  prev.setEmbeddedModularChainInfo(modularChainInfo);
@@ -1333,17 +768,31 @@ class ChainStore {
1333
768
  if (!cosmos) {
1334
769
  throw new Error("Can't find cosmos chain info");
1335
770
  }
1336
- return Object.assign({ chainId: cosmos.chainId, chainName: cosmos.chainName, chainSymbolImageUrl: cosmos.chainSymbolImageUrl, isNative: chainInfo.isNative || !cosmos.beta, cosmos }, (cosmos.evm && {
1337
- evm: Object.assign(Object.assign({}, cosmos.evm), { currencies: cosmos.currencies, bip44: cosmos.bip44 }),
1338
- }));
771
+ return {
772
+ chainId: cosmos.chainId,
773
+ chainName: cosmos.chainName,
774
+ chainSymbolImageUrl: cosmos.chainSymbolImageUrl,
775
+ cosmos,
776
+ };
1339
777
  }
1340
778
  return chainInfo;
1341
779
  });
1342
780
  this._modularChainInfoImpls = infos.modulrChainInfos.map((chainInfo) => {
1343
- const modularChainInfo = this._modularChainInfos.find((c) => c.chainId === chainInfo.chainId);
1344
- if (!modularChainInfo) {
1345
- throw new Error(`Unknown modular chain info: ${chainInfo.chainId}`);
1346
- }
781
+ const modularChainInfo = (() => {
782
+ if ("currencies" in chainInfo) {
783
+ const cosmos = infos.chainInfos.find((c) => c.chainId === chainInfo.chainId);
784
+ if (!cosmos) {
785
+ throw new Error("Can't find cosmos chain info");
786
+ }
787
+ return {
788
+ chainId: cosmos.chainId,
789
+ chainName: cosmos.chainName,
790
+ chainSymbolImageUrl: cosmos.chainSymbolImageUrl,
791
+ cosmos,
792
+ };
793
+ }
794
+ return chainInfo;
795
+ })();
1347
796
  const prev = this.modularChainInfoImplMap.get(cosmos_1.ChainIdHelper.parse(chainInfo.chainId).identifier);
1348
797
  if (prev) {
1349
798
  prev.setEmbeddedModularChainInfo(modularChainInfo);
@@ -1366,8 +815,8 @@ class ChainStore {
1366
815
  this.currencyRegistrars.push(registrar);
1367
816
  }
1368
817
  isEvmChain(chainId) {
1369
- const chainInfo = this.getModularChain(chainId);
1370
- return "evm" in chainInfo && chainInfo.evm != null;
818
+ const chainInfo = this.getChain(chainId);
819
+ return chainInfo.evm != null;
1371
820
  }
1372
821
  isEvmOnlyChain(chainId) {
1373
822
  const chainIdLikeCAIP2 = chainId.split(":");
@@ -1375,26 +824,16 @@ class ChainStore {
1375
824
  chainIdLikeCAIP2.length === 2 &&
1376
825
  chainIdLikeCAIP2[0] === "eip155");
1377
826
  }
1378
- // 초기화 시 isEvmOnlyChain 확인하면 _modularChainInfos 할당 전이라 오류가 발생할 수 밖에 없어서 별도 추가
1379
- isEvmOnlyChainForInit(chainId) {
1380
- const chainIdLikeCAIP2 = chainId.split(":");
1381
- return chainIdLikeCAIP2.length === 2 && chainIdLikeCAIP2[0] === "eip155";
1382
- }
1383
827
  isEvmOrEthermintLikeChain(chainId) {
1384
- var _a, _b, _c, _d;
828
+ var _a, _b;
1385
829
  const b = this.isEvmChain(chainId);
1386
830
  if (b) {
1387
831
  return true;
1388
832
  }
1389
- const chainInfo = this.getModularChain(chainId);
1390
- const isEthermintLike = ("cosmos" in chainInfo &&
1391
- (chainInfo.cosmos.bip44.coinType === 60 ||
1392
- !!((_a = chainInfo.cosmos.features) === null || _a === void 0 ? void 0 : _a.includes("eth-address-gen")) ||
1393
- !!((_b = chainInfo.cosmos.features) === null || _b === void 0 ? void 0 : _b.includes("eth-key-sign")))) ||
1394
- ("evm" in chainInfo &&
1395
- (chainInfo.evm.bip44.coinType === 60 ||
1396
- !!((_c = chainInfo.evm.features) === null || _c === void 0 ? void 0 : _c.includes("eth-address-gen")) ||
1397
- !!((_d = chainInfo.evm.features) === null || _d === void 0 ? void 0 : _d.includes("eth-key-sign"))));
833
+ const chainInfo = this.getChain(chainId);
834
+ const isEthermintLike = chainInfo.bip44.coinType === 60 ||
835
+ !!((_a = chainInfo.features) === null || _a === void 0 ? void 0 : _a.includes("eth-address-gen")) ||
836
+ !!((_b = chainInfo.features) === null || _b === void 0 ? void 0 : _b.includes("eth-key-sign"));
1398
837
  return isEthermintLike;
1399
838
  }
1400
839
  }