@subwallet/extension-base 1.3.22-0 → 1.3.24-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.
Files changed (210) hide show
  1. package/background/KoniTypes.d.ts +77 -4
  2. package/background/KoniTypes.js +2 -0
  3. package/cjs/background/KoniTypes.js +2 -0
  4. package/cjs/constants/environment.js +4 -2
  5. package/cjs/constants/index.js +21 -4
  6. package/cjs/constants/signing.js +6 -2
  7. package/cjs/core/logic-validation/recipientAddress.js +9 -1
  8. package/cjs/core/logic-validation/transfer.js +57 -36
  9. package/cjs/core/types.js +1 -0
  10. package/cjs/core/utils.js +12 -1
  11. package/cjs/defaults.js +1 -1
  12. package/cjs/koni/api/dotsama/crowdloan.js +1 -1
  13. package/cjs/koni/api/nft/index.js +9 -16
  14. package/cjs/koni/api/staking/index.js +3 -4
  15. package/cjs/koni/background/handlers/Extension.js +343 -185
  16. package/cjs/koni/background/handlers/State.js +17 -2
  17. package/cjs/koni/background/handlers/Tabs.js +1 -1
  18. package/cjs/packageInfo.js +1 -1
  19. package/cjs/services/balance-service/helpers/subscribe/cardano/consts.js +11 -0
  20. package/cjs/services/balance-service/helpers/subscribe/cardano/index.js +63 -0
  21. package/cjs/services/balance-service/helpers/subscribe/cardano/types.js +1 -0
  22. package/cjs/services/balance-service/helpers/subscribe/cardano/utils.js +74 -0
  23. package/cjs/services/balance-service/helpers/subscribe/index.js +21 -7
  24. package/cjs/services/balance-service/helpers/subscribe/ton/utils.js +2 -2
  25. package/cjs/services/balance-service/index.js +4 -2
  26. package/cjs/services/balance-service/transfer/cardano-transfer.js +122 -0
  27. package/cjs/services/balance-service/transfer/smart-contract.js +24 -3
  28. package/cjs/services/balance-service/transfer/token.js +4 -4
  29. package/cjs/services/chain-service/handler/CardanoApi.js +176 -0
  30. package/cjs/services/chain-service/handler/CardanoChainHandler.js +83 -0
  31. package/cjs/services/chain-service/handler/TonApi.js +2 -5
  32. package/cjs/services/chain-service/index.js +40 -7
  33. package/cjs/services/chain-service/utils/index.js +40 -11
  34. package/cjs/services/chain-service/utils/patch.js +1 -1
  35. package/cjs/services/earning-service/handlers/liquid-staking/bifrost-manta.js +1 -1
  36. package/cjs/services/earning-service/handlers/liquid-staking/bifrost.js +1 -1
  37. package/cjs/services/earning-service/service.js +6 -12
  38. package/cjs/services/fee-service/service.js +19 -8
  39. package/cjs/services/fee-service/utils/tokenPayFee.js +151 -0
  40. package/cjs/services/history-service/index.js +4 -6
  41. package/cjs/services/inapp-notification-service/index.js +12 -4
  42. package/cjs/services/keyring-service/context/account-context.js +17 -2
  43. package/cjs/services/keyring-service/context/handlers/Derive.js +10 -7
  44. package/cjs/services/keyring-service/context/handlers/Migration.js +268 -0
  45. package/cjs/services/keyring-service/context/handlers/Mnemonic.js +2 -2
  46. package/cjs/services/keyring-service/context/handlers/Secret.js +1 -1
  47. package/cjs/services/keyring-service/utils.js +18 -0
  48. package/cjs/services/request-service/handler/CardanoRequestHandler.js +172 -0
  49. package/cjs/services/request-service/handler/EvmRequestHandler.js +1 -1
  50. package/cjs/services/request-service/handler/MetadataRequestHandler.js +5 -13
  51. package/cjs/services/request-service/index.js +22 -4
  52. package/cjs/services/setting-service/constants.js +10 -1
  53. package/cjs/services/storage-service/DatabaseService.js +3 -0
  54. package/cjs/services/storage-service/db-stores/InappNotification.js +6 -0
  55. package/cjs/services/swap-service/handler/asset-hub/handler.js +0 -59
  56. package/cjs/services/swap-service/handler/chainflip-handler.js +33 -281
  57. package/cjs/services/swap-service/handler/hydradx-handler.js +23 -190
  58. package/cjs/services/swap-service/handler/simpleswap-handler.js +1 -222
  59. package/cjs/services/swap-service/handler/uniswap-handler.js +331 -0
  60. package/cjs/services/swap-service/index.js +31 -22
  61. package/cjs/services/swap-service/utils.js +21 -38
  62. package/cjs/services/transaction-service/helpers/index.js +6 -1
  63. package/cjs/services/transaction-service/index.js +286 -26
  64. package/cjs/services/transaction-service/utils.js +5 -1
  65. package/cjs/types/account/info/keyring.js +12 -1
  66. package/cjs/types/fee/cardano.js +1 -0
  67. package/cjs/types/swap/index.js +7 -2
  68. package/cjs/utils/account/analyze.js +2 -1
  69. package/cjs/utils/account/common.js +29 -20
  70. package/cjs/utils/account/derive/info/solo.js +9 -4
  71. package/cjs/utils/account/derive/validate.js +36 -2
  72. package/cjs/utils/account/transform.js +38 -13
  73. package/cjs/utils/fee/transfer.js +87 -21
  74. package/cjs/utils/index.js +2 -2
  75. package/cjs/utils/staticData/index.js +7 -2
  76. package/constants/environment.d.ts +1 -0
  77. package/constants/environment.js +2 -1
  78. package/constants/index.d.ts +6 -1
  79. package/constants/index.js +14 -1
  80. package/constants/signing.js +6 -2
  81. package/core/logic-validation/recipientAddress.js +11 -3
  82. package/core/logic-validation/transfer.d.ts +1 -1
  83. package/core/logic-validation/transfer.js +33 -12
  84. package/core/substrate/xcm-parser.d.ts +1 -1
  85. package/core/types.d.ts +1 -0
  86. package/core/types.js +1 -0
  87. package/core/utils.d.ts +1 -0
  88. package/core/utils.js +13 -3
  89. package/defaults.d.ts +1 -1
  90. package/defaults.js +1 -1
  91. package/koni/api/dotsama/crowdloan.js +3 -3
  92. package/koni/api/nft/index.js +10 -16
  93. package/koni/api/nft/story_odyssey_nft/index.d.ts +1 -1
  94. package/koni/api/staking/index.js +4 -5
  95. package/koni/background/handlers/Extension.d.ts +9 -0
  96. package/koni/background/handlers/Extension.js +225 -69
  97. package/koni/background/handlers/State.d.ts +6 -2
  98. package/koni/background/handlers/State.js +18 -3
  99. package/koni/background/handlers/Tabs.js +1 -1
  100. package/package.json +76 -9
  101. package/packageInfo.js +1 -1
  102. package/services/balance-service/helpers/subscribe/cardano/consts.d.ts +1 -0
  103. package/services/balance-service/helpers/subscribe/cardano/consts.js +4 -0
  104. package/services/balance-service/helpers/subscribe/cardano/index.d.ts +2 -0
  105. package/services/balance-service/helpers/subscribe/cardano/index.js +57 -0
  106. package/services/balance-service/helpers/subscribe/cardano/types.d.ts +34 -0
  107. package/services/balance-service/helpers/subscribe/cardano/types.js +1 -0
  108. package/services/balance-service/helpers/subscribe/cardano/utils.d.ts +15 -0
  109. package/services/balance-service/helpers/subscribe/cardano/utils.js +62 -0
  110. package/services/balance-service/helpers/subscribe/index.d.ts +2 -2
  111. package/services/balance-service/helpers/subscribe/index.js +23 -9
  112. package/services/balance-service/helpers/subscribe/ton/utils.d.ts +1 -1
  113. package/services/balance-service/helpers/subscribe/ton/utils.js +1 -1
  114. package/services/balance-service/index.js +4 -2
  115. package/services/balance-service/transfer/cardano-transfer.d.ts +24 -0
  116. package/services/balance-service/transfer/cardano-transfer.js +114 -0
  117. package/services/balance-service/transfer/smart-contract.d.ts +4 -2
  118. package/services/balance-service/transfer/smart-contract.js +24 -3
  119. package/services/balance-service/transfer/token.d.ts +1 -1
  120. package/services/balance-service/transfer/token.js +2 -2
  121. package/services/chain-service/handler/CardanoApi.d.ts +38 -0
  122. package/services/chain-service/handler/CardanoApi.js +167 -0
  123. package/services/chain-service/handler/CardanoChainHandler.d.ts +17 -0
  124. package/services/chain-service/handler/CardanoChainHandler.js +75 -0
  125. package/services/chain-service/handler/TonApi.js +3 -6
  126. package/services/chain-service/handler/types.d.ts +1 -0
  127. package/services/chain-service/index.d.ts +4 -1
  128. package/services/chain-service/index.js +41 -8
  129. package/services/chain-service/types.d.ts +9 -1
  130. package/services/chain-service/utils/index.d.ts +4 -0
  131. package/services/chain-service/utils/index.js +32 -11
  132. package/services/chain-service/utils/patch.js +1 -1
  133. package/services/earning-service/handlers/liquid-staking/bifrost-manta.js +1 -1
  134. package/services/earning-service/handlers/liquid-staking/bifrost.js +1 -1
  135. package/services/earning-service/service.js +8 -14
  136. package/services/fee-service/interfaces.d.ts +25 -0
  137. package/services/fee-service/service.js +19 -8
  138. package/services/fee-service/utils/tokenPayFee.d.ts +8 -0
  139. package/services/fee-service/utils/tokenPayFee.js +141 -0
  140. package/services/history-service/index.js +6 -8
  141. package/services/inapp-notification-service/index.d.ts +3 -4
  142. package/services/inapp-notification-service/index.js +14 -6
  143. package/services/keyring-service/context/account-context.d.ts +6 -2
  144. package/services/keyring-service/context/account-context.js +17 -2
  145. package/services/keyring-service/context/handlers/Derive.d.ts +1 -1
  146. package/services/keyring-service/context/handlers/Derive.js +10 -8
  147. package/services/keyring-service/context/handlers/Migration.d.ts +17 -0
  148. package/services/keyring-service/context/handlers/Migration.js +258 -0
  149. package/services/keyring-service/context/handlers/Mnemonic.js +2 -2
  150. package/services/keyring-service/context/handlers/Secret.js +2 -2
  151. package/services/keyring-service/utils.d.ts +2 -0
  152. package/services/keyring-service/utils.js +11 -0
  153. package/services/request-service/handler/CardanoRequestHandler.d.ts +16 -0
  154. package/services/request-service/handler/CardanoRequestHandler.js +163 -0
  155. package/services/request-service/handler/EvmRequestHandler.js +1 -1
  156. package/services/request-service/handler/MetadataRequestHandler.d.ts +1 -1
  157. package/services/request-service/handler/MetadataRequestHandler.js +5 -13
  158. package/services/request-service/index.d.ts +7 -4
  159. package/services/request-service/index.js +21 -7
  160. package/services/setting-service/constants.d.ts +3 -0
  161. package/services/setting-service/constants.js +6 -0
  162. package/services/storage-service/DatabaseService.d.ts +1 -0
  163. package/services/storage-service/DatabaseService.js +3 -0
  164. package/services/storage-service/db-stores/InappNotification.d.ts +1 -0
  165. package/services/storage-service/db-stores/InappNotification.js +6 -0
  166. package/services/swap-service/handler/asset-hub/handler.d.ts +1 -4
  167. package/services/swap-service/handler/asset-hub/handler.js +2 -61
  168. package/services/swap-service/handler/base-handler.d.ts +1 -4
  169. package/services/swap-service/handler/chainflip-handler.d.ts +2 -9
  170. package/services/swap-service/handler/chainflip-handler.js +31 -280
  171. package/services/swap-service/handler/hydradx-handler.d.ts +1 -6
  172. package/services/swap-service/handler/hydradx-handler.js +13 -180
  173. package/services/swap-service/handler/simpleswap-handler.d.ts +1 -4
  174. package/services/swap-service/handler/simpleswap-handler.js +5 -226
  175. package/services/swap-service/handler/uniswap-handler.d.ts +41 -0
  176. package/services/swap-service/handler/uniswap-handler.js +323 -0
  177. package/services/swap-service/index.js +30 -22
  178. package/services/swap-service/utils.d.ts +1 -5
  179. package/services/swap-service/utils.js +7 -21
  180. package/services/transaction-service/helpers/index.d.ts +2 -0
  181. package/services/transaction-service/helpers/index.js +4 -0
  182. package/services/transaction-service/index.d.ts +8 -2
  183. package/services/transaction-service/index.js +273 -17
  184. package/services/transaction-service/types.d.ts +7 -0
  185. package/services/transaction-service/utils.js +7 -2
  186. package/types/account/info/keyring.d.ts +4 -1
  187. package/types/account/info/keyring.js +9 -0
  188. package/types/account/info/proxy.d.ts +2 -0
  189. package/types/balance/index.d.ts +4 -1
  190. package/types/fee/base.d.ts +1 -1
  191. package/types/fee/cardano.d.ts +18 -0
  192. package/types/fee/cardano.js +1 -0
  193. package/types/fee/option.d.ts +1 -1
  194. package/types/fee/subscription.d.ts +4 -3
  195. package/types/swap/index.d.ts +11 -3
  196. package/types/swap/index.js +7 -2
  197. package/utils/account/analyze.js +2 -1
  198. package/utils/account/common.d.ts +11 -6
  199. package/utils/account/common.js +28 -19
  200. package/utils/account/derive/info/solo.js +10 -5
  201. package/utils/account/derive/validate.d.ts +1 -0
  202. package/utils/account/derive/validate.js +34 -1
  203. package/utils/account/transform.d.ts +2 -1
  204. package/utils/account/transform.js +37 -13
  205. package/utils/fee/transfer.d.ts +3 -2
  206. package/utils/fee/transfer.js +90 -24
  207. package/utils/index.js +4 -4
  208. package/utils/staticData/index.d.ts +4 -1
  209. package/utils/staticData/index.js +5 -1
  210. package/utils/staticData/oldChainPrefix.json +1 -0
@@ -1,4 +1,5 @@
1
1
  import { ChainType, ExtrinsicDataTypeMap, ExtrinsicStatus, ExtrinsicType, FeeData, ValidateTransactionResponse } from '@subwallet/extension-base/background/KoniTypes';
2
+ import { SignTypedDataMessageV3V4 } from '@subwallet/extension-base/core/logic-validation';
2
3
  import { TonTransactionConfig } from '@subwallet/extension-base/services/balance-service/transfer/ton-transfer';
3
4
  import { BaseRequestSign, BriefProcessStep, ProcessTransactionData, TransactionFee } from '@subwallet/extension-base/types';
4
5
  import EventEmitter from 'eventemitter3';
@@ -27,6 +28,9 @@ export interface SWTransaction extends ValidateTransactionResponse, Partial<Pick
27
28
  signAfterCreate?: (id: string) => void;
28
29
  step?: BriefProcessStep;
29
30
  }
31
+ export interface SWPermitTransaction extends Omit<SWTransaction, 'transaction'> {
32
+ transaction: SignTypedDataMessageV3V4;
33
+ }
30
34
  export interface SWTransactionResult extends Omit<SWTransaction, 'transaction' | 'additionalValidator' | 'eventsHandler' | 'process'> {
31
35
  process?: ProcessTransactionData;
32
36
  }
@@ -42,6 +46,9 @@ export interface SWTransactionInput extends SwInputBase, Partial<Pick<SWTransact
42
46
  resolveOnDone?: boolean;
43
47
  skipFeeValidation?: boolean;
44
48
  }
49
+ export interface SWPermitTransactionInput extends Omit<SWTransactionInput, 'transaction'> {
50
+ transaction?: SWPermitTransaction['transaction'] | null;
51
+ }
45
52
  export declare type SWTransactionResponse = SwInputBase & Pick<SWTransaction, 'warnings' | 'errors'> & Partial<Pick<SWTransaction, 'id' | 'extrinsicHash' | 'status' | 'estimateFee'>> & TransactionFee & {
46
53
  processId?: string;
47
54
  };
@@ -1,8 +1,10 @@
1
1
  // Copyright 2019-2022 @subwallet/extension-base authors & contributors
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- import { _getBlockExplorerFromChain, _isChainTestNet, _isPureEvmChain } from '@subwallet/extension-base/services/chain-service/utils';
4
+ import { _getBlockExplorerFromChain, _isChainTestNet, _isPureCardanoChain, _isPureEvmChain } from '@subwallet/extension-base/services/chain-service/utils';
5
5
  import { CHAIN_FLIP_MAINNET_EXPLORER, CHAIN_FLIP_TESTNET_EXPLORER, SIMPLE_SWAP_EXPLORER } from '@subwallet/extension-base/services/swap-service/utils';
6
+ import { hexAddPrefix, isHex } from '@polkadot/util';
7
+
6
8
  // @ts-ignore
7
9
  export function parseTransactionData(data) {
8
10
  // @ts-ignore
@@ -46,6 +48,9 @@ function getBlockExplorerTxRoute(chainInfo) {
46
48
  if (_isPureEvmChain(chainInfo)) {
47
49
  return 'tx';
48
50
  }
51
+ if (_isPureCardanoChain(chainInfo)) {
52
+ return 'transaction';
53
+ }
49
54
  if (['aventus', 'deeper_network'].includes(chainInfo.slug)) {
50
55
  return 'transaction';
51
56
  }
@@ -60,7 +65,7 @@ export function getExplorerLink(chainInfo, value, type) {
60
65
  const route = getBlockExplorerAccountRoute(explorerLink);
61
66
  return `${explorerLink}${explorerLink.endsWith('/') ? '' : '/'}${route}/${value}`;
62
67
  }
63
- if (explorerLink && value.startsWith('0x')) {
68
+ if (explorerLink && isHex(hexAddPrefix(value))) {
64
69
  if (chainInfo.slug === 'bittensor') {
65
70
  return undefined;
66
71
  }
@@ -112,8 +112,11 @@ export declare enum AccountChainType {
112
112
  SUBSTRATE = "substrate",
113
113
  ETHEREUM = "ethereum",
114
114
  BITCOIN = "bitcoin",
115
- TON = "ton"
115
+ TON = "ton",
116
+ CARDANO = "cardano"
116
117
  }
118
+ export declare const ACCOUNT_CHAIN_TYPE_ORDINAL_MAP: Record<string, number>;
119
+ export declare const SUPPORTED_ACCOUNT_CHAIN_TYPES: string[];
117
120
  export declare enum AccountActions {
118
121
  DERIVE = "DERIVE",
119
122
  EXPORT_MNEMONIC = "EXPORT_MNEMONIC",
@@ -65,7 +65,16 @@ export let AccountChainType;
65
65
  AccountChainType["ETHEREUM"] = "ethereum";
66
66
  AccountChainType["BITCOIN"] = "bitcoin";
67
67
  AccountChainType["TON"] = "ton";
68
+ AccountChainType["CARDANO"] = "cardano";
68
69
  })(AccountChainType || (AccountChainType = {}));
70
+ export const ACCOUNT_CHAIN_TYPE_ORDINAL_MAP = {
71
+ [AccountChainType.SUBSTRATE]: 1,
72
+ [AccountChainType.ETHEREUM]: 2,
73
+ [AccountChainType.TON]: 3,
74
+ [AccountChainType.CARDANO]: 4,
75
+ [AccountChainType.BITCOIN]: 5
76
+ };
77
+ export const SUPPORTED_ACCOUNT_CHAIN_TYPES = ['substrate', 'ethereum', 'ton', 'cardano'];
69
78
  export let AccountActions;
70
79
 
71
80
  /**
@@ -15,6 +15,7 @@ export interface AccountProxyData {
15
15
  name: string;
16
16
  parentId?: string;
17
17
  suri?: string;
18
+ isMigrationDone?: boolean;
18
19
  }
19
20
  /**
20
21
  * Represents a mapping of unique identifiers to account proxy data.
@@ -55,6 +56,7 @@ export interface AccountProxy extends AccountProxyData {
55
56
  children?: string[];
56
57
  tokenTypes: _AssetType[];
57
58
  accountActions: AccountActions[];
59
+ isNeedMigrateUnifiedAccount?: boolean;
58
60
  }
59
61
  export declare type AccountProxyMap = Record<string, AccountProxy>;
60
62
  export interface AccountProxyExtra extends AccountProxy {
@@ -1,7 +1,7 @@
1
1
  /// <reference types="bn.js" />
2
2
  import { _ChainAsset, _ChainInfo } from '@subwallet/chain-list/types';
3
3
  import { _BalanceMetadata, APIItemState, ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
4
- import { _EvmApi, _SubstrateApi, _TonApi } from '@subwallet/extension-base/services/chain-service/types';
4
+ import { _CardanoApi, _EvmApi, _SubstrateApi, _TonApi } from '@subwallet/extension-base/services/chain-service/types';
5
5
  import { BN } from '@polkadot/util';
6
6
  export interface TokenBalanceRaw {
7
7
  reserved: BN;
@@ -52,3 +52,6 @@ export interface SubscribeEvmPalletBalance extends SubscribeBasePalletBalance {
52
52
  export interface SubscribeTonPalletBalance extends SubscribeBasePalletBalance {
53
53
  tonApi: _TonApi;
54
54
  }
55
+ export interface SusbcribeCardanoPalletBalance extends SubscribeBasePalletBalance {
56
+ cardanoApi: _CardanoApi;
57
+ }
@@ -1,4 +1,4 @@
1
- export declare type FeeChainType = 'evm' | 'substrate' | 'ton';
1
+ export declare type FeeChainType = 'evm' | 'substrate' | 'ton' | 'cardano';
2
2
  export interface BaseFeeInfo {
3
3
  busyNetwork: boolean;
4
4
  type: FeeChainType;
@@ -0,0 +1,18 @@
1
+ import { BaseFeeDetail, BaseFeeInfo } from './base';
2
+ import { FeeDefaultOption } from './option';
3
+ /** @deprecated */
4
+ export interface CardanoTipInfo {
5
+ tip: string;
6
+ }
7
+ /** @deprecated */
8
+ export interface CardanoFeeInfo extends BaseFeeInfo {
9
+ type: 'ton';
10
+ options: {
11
+ slow: CardanoTipInfo;
12
+ average: CardanoTipInfo;
13
+ fast: CardanoTipInfo;
14
+ default: FeeDefaultOption;
15
+ };
16
+ }
17
+ /** @deprecated */
18
+ export declare type CardanoFeeDetail = CardanoFeeInfo & BaseFeeDetail;
@@ -0,0 +1 @@
1
+ export {};
@@ -4,5 +4,5 @@ export declare type FeeOption = FeeDefaultOption | 'custom';
4
4
  export declare type TransactionFee = {
5
5
  feeOption?: FeeOption;
6
6
  feeCustom?: FeeCustom;
7
- nonNativeTokenPayFeeSlug?: string;
7
+ tokenPayFeeSlug?: string;
8
8
  };
@@ -1,10 +1,11 @@
1
1
  import { BehaviorSubject } from 'rxjs';
2
+ import { CardanoFeeDetail, CardanoFeeInfo, CardanoTipInfo } from './cardano';
2
3
  import { EvmEIP1559FeeOption, EvmFeeDetail, EvmFeeInfo } from './evm';
3
4
  import { SubstrateFeeDetail, SubstrateFeeInfo, SubstrateTipInfo } from './substrate';
4
5
  import { TonFeeDetail, TonFeeInfo, TonTipInfo } from './ton';
5
- export declare type FeeInfo = EvmFeeInfo | SubstrateFeeInfo | TonFeeInfo;
6
- export declare type FeeDetail = EvmFeeDetail | SubstrateFeeDetail | TonFeeDetail;
7
- export declare type FeeCustom = EvmEIP1559FeeOption | SubstrateTipInfo | TonTipInfo;
6
+ export declare type FeeInfo = EvmFeeInfo | SubstrateFeeInfo | TonFeeInfo | CardanoFeeInfo;
7
+ export declare type FeeDetail = EvmFeeDetail | SubstrateFeeDetail | TonFeeDetail | CardanoFeeDetail;
8
+ export declare type FeeCustom = EvmEIP1559FeeOption | SubstrateTipInfo | TonTipInfo | CardanoTipInfo;
8
9
  export interface FeeSubscription {
9
10
  observer: BehaviorSubject<FeeInfo | undefined>;
10
11
  subscription: Record<string, VoidFunction>;
@@ -1,7 +1,7 @@
1
1
  import { _ChainInfo } from '@subwallet/chain-list/types';
2
2
  import { SwapError } from '@subwallet/extension-base/background/errors/SwapError';
3
3
  import { AmountData, ChainType, ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
4
- import { BaseStepDetail, CommonOptimalPath, CommonStepFeeInfo } from '@subwallet/extension-base/types/service-base';
4
+ import { BaseStepDetail, BaseStepType, CommonOptimalPath, CommonStepFeeInfo } from '@subwallet/extension-base/types/service-base';
5
5
  import BigN from 'bignumber.js';
6
6
  import { BaseProcessRequestSign, TransactionData } from '../transaction';
7
7
  export declare type SwapRate = number;
@@ -44,7 +44,8 @@ export declare enum SwapErrorType {
44
44
  NOT_MEET_MIN_EXPECTED = "NOT_MEET_MIN_EXPECTED"
45
45
  }
46
46
  export declare enum SwapStepType {
47
- SWAP = "SWAP"
47
+ SWAP = "SWAP",
48
+ PERMIT = "PERMIT"
48
49
  }
49
50
  export declare enum SwapProviderId {
50
51
  CHAIN_FLIP_TESTNET = "CHAIN_FLIP_TESTNET",
@@ -55,7 +56,8 @@ export declare enum SwapProviderId {
55
56
  KUSAMA_ASSET_HUB = "KUSAMA_ASSET_HUB",
56
57
  ROCOCO_ASSET_HUB = "ROCOCO_ASSET_HUB",
57
58
  WESTEND_ASSET_HUB = "WESTEND_ASSET_HUB",
58
- SIMPLE_SWAP = "SIMPLE_SWAP"
59
+ SIMPLE_SWAP = "SIMPLE_SWAP",
60
+ UNISWAP = "UNISWAP"
59
61
  }
60
62
  export declare const _SUPPORTED_SWAP_PROVIDERS: SwapProviderId[];
61
63
  export interface SwapProvider {
@@ -139,6 +141,7 @@ export interface SwapSubmitParams extends BaseProcessRequestSign {
139
141
  address: string;
140
142
  slippage: number;
141
143
  recipient?: string;
144
+ cacheProcessId: string;
142
145
  }
143
146
  export interface SwapSubmitStepData {
144
147
  txChain: string;
@@ -147,6 +150,7 @@ export interface SwapSubmitStepData {
147
150
  transferNativeAmount: string;
148
151
  extrinsicType: ExtrinsicType;
149
152
  chainType: ChainType;
153
+ isPermit?: boolean;
150
154
  }
151
155
  export interface OptimalSwapPathParams {
152
156
  request: SwapRequest;
@@ -169,5 +173,9 @@ export interface SlippageType {
169
173
  slippage: BigN;
170
174
  isCustomType: boolean;
171
175
  }
176
+ export interface PermitSwapData {
177
+ processId: string;
178
+ step: BaseStepType;
179
+ }
172
180
  export declare const CHAINFLIP_SLIPPAGE = 0.02;
173
181
  export declare const SIMPLE_SWAP_SLIPPAGE = 0.05;
@@ -21,6 +21,7 @@ export let SwapErrorType;
21
21
  export let SwapStepType;
22
22
  (function (SwapStepType) {
23
23
  SwapStepType["SWAP"] = "SWAP";
24
+ SwapStepType["PERMIT"] = "PERMIT";
24
25
  })(SwapStepType || (SwapStepType = {}));
25
26
  export let SwapProviderId;
26
27
  (function (SwapProviderId) {
@@ -33,10 +34,14 @@ export let SwapProviderId;
33
34
  SwapProviderId["ROCOCO_ASSET_HUB"] = "ROCOCO_ASSET_HUB";
34
35
  SwapProviderId["WESTEND_ASSET_HUB"] = "WESTEND_ASSET_HUB";
35
36
  SwapProviderId["SIMPLE_SWAP"] = "SIMPLE_SWAP";
37
+ SwapProviderId["UNISWAP"] = "UNISWAP";
36
38
  })(SwapProviderId || (SwapProviderId = {}));
37
- export const _SUPPORTED_SWAP_PROVIDERS = [SwapProviderId.CHAIN_FLIP_TESTNET, SwapProviderId.CHAIN_FLIP_MAINNET, SwapProviderId.HYDRADX_MAINNET, SwapProviderId.HYDRADX_TESTNET, SwapProviderId.POLKADOT_ASSET_HUB, SwapProviderId.KUSAMA_ASSET_HUB, SwapProviderId.ROCOCO_ASSET_HUB,
39
+ export const _SUPPORTED_SWAP_PROVIDERS = [SwapProviderId.CHAIN_FLIP_TESTNET, SwapProviderId.CHAIN_FLIP_MAINNET, SwapProviderId.HYDRADX_MAINNET,
40
+ // SwapProviderId.HYDRADX_TESTNET,
41
+ SwapProviderId.POLKADOT_ASSET_HUB, SwapProviderId.KUSAMA_ASSET_HUB,
42
+ // SwapProviderId.ROCOCO_ASSET_HUB,
38
43
  // SwapProviderId.WESTEND_ASSET_HUB,
39
- SwapProviderId.SIMPLE_SWAP];
44
+ SwapProviderId.SIMPLE_SWAP, SwapProviderId.UNISWAP];
40
45
  // process handling
41
46
  export let SwapFeeType;
42
47
  (function (SwapFeeType) {
@@ -15,7 +15,8 @@ const isStrValidWithAddress = (str, account, chainInfo) => {
15
15
  } else if (account.address.toLowerCase().includes(str) || reformated.toLowerCase().includes(str)) {
16
16
  return 'valid';
17
17
  }
18
- } else if (account.chainType === AccountChainType.TON) {
18
+ } else if (account.chainType === AccountChainType.TON || account.chainType === AccountChainType.CARDANO) {
19
+ // todo: recheck for Cardano
19
20
  const isTestnet = chainInfo.isTestnet;
20
21
  const reformated = reformatAddress(account.address, isTestnet ? 0 : 1);
21
22
  if (account.address.toLowerCase() === str || reformated.toLowerCase() === str) {
@@ -1,16 +1,21 @@
1
1
  import { _ChainInfo } from '@subwallet/chain-list/types';
2
+ import { ChainType } from '@subwallet/extension-base/background/KoniTypes';
2
3
  import { AccountChainType } from '@subwallet/extension-base/types';
3
4
  import { KeypairType } from '@subwallet/keyring/types';
4
5
  export declare function isAccountAll(address?: string): boolean;
5
6
  export declare function reformatAddress(address: string, networkPrefix?: number, isEthereum?: boolean): string;
6
7
  export declare const _reformatAddressWithChain: (address: string, chainInfo: _ChainInfo) => string;
7
8
  export declare const getAccountChainTypeForAddress: (address: string) => AccountChainType;
8
- export declare function categoryAddresses(addresses: string[]): {
9
- substrate: string[];
10
- evm: string[];
11
- ton: string[];
12
- bitcoin: string[];
13
- };
9
+ interface AddressesByChainType {
10
+ [ChainType.SUBSTRATE]: string[];
11
+ [ChainType.EVM]: string[];
12
+ [ChainType.BITCOIN]: string[];
13
+ [ChainType.TON]: string[];
14
+ [ChainType.CARDANO]: string[];
15
+ }
16
+ export declare function getAddressesByChainType(addresses: string[], chainTypes: ChainType[]): string[];
17
+ export declare function getAddressesByChainTypeMap(addresses: string[]): AddressesByChainType;
14
18
  export declare function quickFormatAddressToCompare(address?: string): string | undefined;
15
19
  /** @deprecated */
16
20
  export declare const modifyAccountName: (type: KeypairType, name: string, modify: boolean) => string;
21
+ export {};
@@ -1,11 +1,12 @@
1
1
  // Copyright 2019-2022 @subwallet/extension-base authors & contributors
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
+ import { ChainType } from '@subwallet/extension-base/background/KoniTypes';
4
5
  import { ALL_ACCOUNT_KEY } from '@subwallet/extension-base/constants';
5
6
  import { _chainInfoToChainType, _getChainSubstrateAddressPrefix } from '@subwallet/extension-base/services/chain-service/utils';
6
7
  import { AccountChainType } from '@subwallet/extension-base/types';
7
- import { getAccountChainType } from '@subwallet/extension-base/utils';
8
- import { decodeAddress, encodeAddress, getKeypairTypeByAddress, isAddress, isBitcoinAddress, isTonAddress } from '@subwallet/keyring';
8
+ import { getAccountChainTypeFromKeypairType } from '@subwallet/extension-base/utils';
9
+ import { decodeAddress, encodeAddress, getKeypairTypeByAddress, isAddress, isBitcoinAddress, isCardanoAddress, isTonAddress } from '@subwallet/keyring';
9
10
  import { ethereumEncode, isEthereumAddress } from '@polkadot/util-crypto';
10
11
  export function isAccountAll(address) {
11
12
  return address === ALL_ACCOUNT_KEY;
@@ -36,10 +37,11 @@ export function reformatAddress(address, networkPrefix = 42, isEthereum = false)
36
37
  }
37
38
  }
38
39
  export const _reformatAddressWithChain = (address, chainInfo) => {
40
+ // todo: check for cardano
39
41
  const chainType = _chainInfoToChainType(chainInfo);
40
42
  if (chainType === AccountChainType.SUBSTRATE) {
41
43
  return reformatAddress(address, _getChainSubstrateAddressPrefix(chainInfo));
42
- } else if (chainType === AccountChainType.TON) {
44
+ } else if (chainType === AccountChainType.TON || chainType === AccountChainType.CARDANO) {
43
45
  const isTestnet = chainInfo.isTestnet;
44
46
  return reformatAddress(address, isTestnet ? 0 : 1);
45
47
  } else {
@@ -48,30 +50,37 @@ export const _reformatAddressWithChain = (address, chainInfo) => {
48
50
  };
49
51
  export const getAccountChainTypeForAddress = address => {
50
52
  const type = getKeypairTypeByAddress(address);
51
- return getAccountChainType(type);
53
+ return getAccountChainTypeFromKeypairType(type);
52
54
  };
53
- export function categoryAddresses(addresses) {
54
- const substrate = [];
55
- const evm = [];
56
- const ton = [];
57
- const bitcoin = [];
55
+ export function getAddressesByChainType(addresses, chainTypes) {
56
+ const addressByChainTypeMap = getAddressesByChainTypeMap(addresses);
57
+ return chainTypes.map(chainType => {
58
+ return addressByChainTypeMap[chainType];
59
+ }).flat(); // todo: recheck
60
+ }
61
+
62
+ export function getAddressesByChainTypeMap(addresses) {
63
+ const addressByChainType = {
64
+ substrate: [],
65
+ evm: [],
66
+ bitcoin: [],
67
+ ton: [],
68
+ cardano: []
69
+ };
58
70
  addresses.forEach(address => {
59
71
  if (isEthereumAddress(address)) {
60
- evm.push(address);
72
+ addressByChainType.evm.push(address);
61
73
  } else if (isTonAddress(address)) {
62
- ton.push(address);
74
+ addressByChainType.ton.push(address);
63
75
  } else if (isBitcoinAddress(address)) {
64
- bitcoin.push(address);
76
+ addressByChainType.bitcoin.push(address);
77
+ } else if (isCardanoAddress(address)) {
78
+ addressByChainType.cardano.push(address);
65
79
  } else {
66
- substrate.push(address);
80
+ addressByChainType.substrate.push(address);
67
81
  }
68
82
  });
69
- return {
70
- bitcoin,
71
- evm,
72
- substrate,
73
- ton
74
- };
83
+ return addressByChainType;
75
84
  }
76
85
  export function quickFormatAddressToCompare(address) {
77
86
  if (!isAddress(address)) {
@@ -6,7 +6,7 @@ import { EthereumKeypairTypes, SubstrateKeypairTypes } from '@subwallet/keyring/
6
6
  import { keyring } from '@subwallet/ui-keyring';
7
7
  import { t } from 'i18next';
8
8
  import { assert } from '@polkadot/util';
9
- import { validateEvmDerivationPath, validateOtherSubstrateDerivationPath, validateSr25519DerivationPath, validateTonDerivationPath, validateUnifiedDerivationPath } from "../validate.js";
9
+ import { validateCardanoDerivationPath, validateEvmDerivationPath, validateOtherSubstrateDerivationPath, validateSr25519DerivationPath, validateTonDerivationPath, validateUnifiedDerivationPath } from "../validate.js";
10
10
  export const parseUnifiedSuriToDerivationPath = (suri, type) => {
11
11
  const reg = /^\/\/(\d+)(\/\/\d+)?$/;
12
12
  if (suri.match(reg)) {
@@ -18,12 +18,16 @@ export const parseUnifiedSuriToDerivationPath = (suri, type) => {
18
18
  return `m/44'/60'/0'/0/${first}/${secondIndex}`;
19
19
  } else if (type === 'ton') {
20
20
  return `m/44'/607'/${first}'/${secondIndex}'`;
21
+ } else if (type === 'cardano') {
22
+ return `m/1852'/1815'/${first}'/${secondIndex}'`;
21
23
  }
22
24
  } else {
23
25
  if (type === 'ethereum') {
24
26
  return `m/44'/60'/0'/0/${first}`;
25
27
  } else if (type === 'ton') {
26
28
  return `m/44'/607'/${first}'`;
29
+ } else if (type === 'cardano') {
30
+ return `m/1852'/1815'/${first}'`;
27
31
  }
28
32
  }
29
33
  if (SubstrateKeypairTypes.includes(type)) {
@@ -40,7 +44,7 @@ export const getSoloDerivationInfo = (type, metadata = {}) => {
40
44
  } = metadata;
41
45
  if (suri) {
42
46
  if (derivePath) {
43
- const validateTypeFunc = type === 'ethereum' ? validateEvmDerivationPath : type === 'ton' ? validateTonDerivationPath : () => undefined;
47
+ const validateTypeFunc = type === 'ethereum' ? validateEvmDerivationPath : type === 'ton' ? validateTonDerivationPath : type === 'cardano' ? validateCardanoDerivationPath : () => undefined;
44
48
  const validateTypeRs = validateTypeFunc(derivePath);
45
49
  if (validateTypeRs) {
46
50
  return {
@@ -97,7 +101,7 @@ export const getSoloDerivationInfo = (type, metadata = {}) => {
97
101
  }
98
102
  } else {
99
103
  if (derivePath) {
100
- const validateTypeFunc = type === 'ethereum' ? validateEvmDerivationPath : type === 'ton' ? validateTonDerivationPath : () => undefined;
104
+ const validateTypeFunc = type === 'ethereum' ? validateEvmDerivationPath : type === 'ton' ? validateTonDerivationPath : type === 'cardano' ? validateCardanoDerivationPath : () => undefined;
101
105
  const validateTypeRs = validateTypeFunc(derivePath);
102
106
  if (validateTypeRs) {
103
107
  return {
@@ -210,6 +214,7 @@ export const derivePair = (parentPair, name, suri, derivationPath) => {
210
214
  }
211
215
  const isEvm = EthereumKeypairTypes.includes(parentPair.type);
212
216
  const isTon = parentPair.type === 'ton';
217
+ const isCardano = parentPair.type === 'cardano';
213
218
  const meta = {
214
219
  name,
215
220
  parentAddress: parentPair.address,
@@ -220,8 +225,8 @@ export const derivePair = (parentPair, name, suri, derivationPath) => {
220
225
  if (isTon && (_parentPair$ton = parentPair.ton) !== null && _parentPair$ton !== void 0 && _parentPair$ton.contractVersion) {
221
226
  meta.tonContractVersion = parentPair.ton.contractVersion;
222
227
  }
223
- if (derivationPath && (isEvm || isTon)) {
224
- return isEvm ? parentPair.evm.deriveCustom(derivationPath, meta) : parentPair.ton.deriveCustom(derivationPath, meta);
228
+ if (derivationPath && (isEvm || isTon || isCardano)) {
229
+ return isEvm ? parentPair.evm.deriveCustom(derivationPath, meta) : isTon ? parentPair.ton.deriveCustom(derivationPath, meta) : parentPair.cardano.deriveCustom(derivationPath, meta);
225
230
  } else {
226
231
  return parentPair.substrate.derive(suri, meta);
227
232
  }
@@ -3,6 +3,7 @@ import { KeypairType, SubstrateKeypairType } from '@subwallet/keyring/types';
3
3
  export declare const validateUnifiedDerivationPath: (raw: string) => DerivePathInfo | undefined;
4
4
  export declare const validateEvmDerivationPath: (raw: string) => IDerivePathInfo_ | undefined;
5
5
  export declare const validateTonDerivationPath: (raw: string) => IDerivePathInfo_ | undefined;
6
+ export declare const validateCardanoDerivationPath: (raw: string) => IDerivePathInfo_ | undefined;
6
7
  export declare const validateSr25519DerivationPath: (raw: string) => IDerivePathInfo_ | undefined;
7
8
  export declare const validateOtherSubstrateDerivationPath: (raw: string, type: Exclude<SubstrateKeypairType, 'sr25519'>) => IDerivePathInfo_ | undefined;
8
9
  export declare const validateDerivationPath: (raw: string, type?: KeypairType) => DerivePathInfo | undefined;
@@ -96,6 +96,37 @@ export const validateTonDerivationPath = raw => {
96
96
  return undefined;
97
97
  }
98
98
  };
99
+ export const validateCardanoDerivationPath = raw => {
100
+ const reg = /^m\/1852'\/1815'\/(\d+)'(\/\d+')?$/;
101
+ if (raw.match(reg)) {
102
+ const [, firstIndex, secondData] = raw.match(reg);
103
+ const first = parseInt(firstIndex, 10);
104
+ const autoIndexes = [first];
105
+ let depth;
106
+ let suri = `//${first}`;
107
+ if (first === 0) {
108
+ depth = 0;
109
+ } else {
110
+ depth = 1;
111
+ }
112
+ if (secondData) {
113
+ const [, secondIndex] = secondData.match(/\/(\d+)/);
114
+ const second = parseInt(secondIndex, 10);
115
+ autoIndexes.push(second);
116
+ depth = 2;
117
+ suri += `//${second}`;
118
+ }
119
+ return {
120
+ depth,
121
+ type: 'cardano',
122
+ suri,
123
+ derivationPath: raw,
124
+ autoIndexes
125
+ };
126
+ } else {
127
+ return undefined;
128
+ }
129
+ };
99
130
  export const validateSr25519DerivationPath = raw => {
100
131
  const reg = /\/(\/?)([^/]+)/g;
101
132
  const parts = raw.match(reg);
@@ -156,10 +187,12 @@ export const validateDerivationPath = (raw, type) => {
156
187
  return validateSr25519DerivationPath(raw);
157
188
  } else if (type === 'ed25519' || type === 'ecdsa') {
158
189
  return validateOtherSubstrateDerivationPath(raw, type);
190
+ } else if (type === 'cardano') {
191
+ return validateCardanoDerivationPath(raw);
159
192
  } else {
160
193
  return undefined;
161
194
  }
162
195
  } else {
163
- return validateUnifiedDerivationPath(raw) || validateEvmDerivationPath(raw) || validateTonDerivationPath(raw) || validateSr25519DerivationPath(raw);
196
+ return validateUnifiedDerivationPath(raw) || validateEvmDerivationPath(raw) || validateTonDerivationPath(raw) || validateSr25519DerivationPath(raw) || validateCardanoDerivationPath(raw);
164
197
  }
165
198
  };
@@ -4,7 +4,8 @@ import { AccountActions, AccountChainType, AccountJson, AccountProxy, AccountPro
4
4
  import { KeypairType, KeyringPair, KeyringPair$Meta } from '@subwallet/keyring/types';
5
5
  import { SingleAddress, SubjectInfo } from '@subwallet/ui-keyring/observable/types';
6
6
  export declare const createAccountProxyId: (_suri: string, derivationPath?: string) => `0x${string}`;
7
- export declare const getAccountChainType: (type: KeypairType) => AccountChainType;
7
+ export declare const getAccountChainTypeFromKeypairType: (type: KeypairType) => AccountChainType;
8
+ export declare const getDefaultKeypairTypeFromAccountChainType: (type: AccountChainType) => KeypairType;
8
9
  export declare const getAccountSignMode: (address: string, _meta?: KeyringPair$Meta) => AccountSignMode;
9
10
  export declare const getAccountActions: (signMode: AccountSignMode, networkType: AccountChainType, type: KeypairType, _meta?: KeyringPair$Meta, parentAccount?: AccountJson) => AccountActions[];
10
11
  export declare const getAccountTransactionActions: (signMode: AccountSignMode, networkType: AccountChainType, type?: KeypairType, _meta?: KeyringPair$Meta, _specialNetwork?: string) => ExtrinsicType[];