@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,39 +1,23 @@
1
1
  // Copyright 2019-2022 @subwallet/extension-base
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- import { SwapSDK } from '@chainflip/sdk/swap';
5
4
  import { COMMON_ASSETS } from '@subwallet/chain-list';
6
- import { SwapError } from '@subwallet/extension-base/background/errors/SwapError';
7
5
  import { TransactionError } from '@subwallet/extension-base/background/errors/TransactionError';
8
6
  import { ChainType, ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
9
- import { _getChainflipEarlyValidationError } from '@subwallet/extension-base/core/logic-validation/swap';
10
7
  import { getERC20TransactionObject, getEVMTransactionObject } from '@subwallet/extension-base/services/balance-service/transfer/smart-contract';
11
- import { createTransferExtrinsic } from '@subwallet/extension-base/services/balance-service/transfer/token';
12
- import { _getAssetDecimals, _getAssetSymbol, _getChainNativeTokenSlug, _getContractAddressOfToken, _isChainSubstrateCompatible, _isNativeToken, _isSmartContractToken } from '@subwallet/extension-base/services/chain-service/utils';
8
+ import { createSubstrateExtrinsic } from '@subwallet/extension-base/services/balance-service/transfer/token';
9
+ import { _getAssetSymbol, _getContractAddressOfToken, _isChainSubstrateCompatible, _isNativeToken } from '@subwallet/extension-base/services/chain-service/utils';
13
10
  import { SwapBaseHandler } from '@subwallet/extension-base/services/swap-service/handler/base-handler';
14
- import { calculateSwapRate, CHAIN_FLIP_SUPPORTED_MAINNET_ASSET_MAPPING, CHAIN_FLIP_SUPPORTED_MAINNET_MAPPING, CHAIN_FLIP_SUPPORTED_TESTNET_ASSET_MAPPING, CHAIN_FLIP_SUPPORTED_TESTNET_MAPPING, getChainflipOptions, SWAP_QUOTE_TIMEOUT_MAP } from '@subwallet/extension-base/services/swap-service/utils';
11
+ import { getChainflipSwap } from '@subwallet/extension-base/services/swap-service/utils';
15
12
  import { BasicTxErrorType } from '@subwallet/extension-base/types';
16
13
  import { CommonStepType } from '@subwallet/extension-base/types/service-base';
17
- import { SwapErrorType, SwapFeeType, SwapProviderId, SwapStepType } from '@subwallet/extension-base/types/swap';
14
+ import { SwapProviderId, SwapStepType } from '@subwallet/extension-base/types/swap';
15
+ import { _reformatAddressWithChain } from '@subwallet/extension-base/utils';
18
16
  import { getId } from '@subwallet/extension-base/utils/getId';
19
17
  import BigNumber from 'bignumber.js';
20
- var ChainflipFeeType;
21
- (function (ChainflipFeeType) {
22
- ChainflipFeeType["INGRESS"] = "INGRESS";
23
- ChainflipFeeType["NETWORK"] = "NETWORK";
24
- ChainflipFeeType["EGRESS"] = "EGRESS";
25
- ChainflipFeeType["BOOST"] = "BOOST";
26
- ChainflipFeeType["BROKER"] = "BROKER";
27
- })(ChainflipFeeType || (ChainflipFeeType = {}));
28
18
  const INTERMEDIARY_MAINNET_ASSET_SLUG = COMMON_ASSETS.USDC_ETHEREUM;
29
19
  const INTERMEDIARY_TESTNET_ASSET_SLUG = COMMON_ASSETS.USDC_SEPOLIA;
30
20
  export const CHAINFLIP_BROKER_API = process.env.CHAINFLIP_BROKER_API || '';
31
- var CHAINFLIP_QUOTE_ERROR;
32
- (function (CHAINFLIP_QUOTE_ERROR) {
33
- CHAINFLIP_QUOTE_ERROR["InsufficientLiquidity"] = "InsufficientLiquidity";
34
- CHAINFLIP_QUOTE_ERROR["InsufficientEgress"] = "is lower than minimum egress amount";
35
- CHAINFLIP_QUOTE_ERROR["InsufficientIngress"] = "amount is lower than estimated ingress fee";
36
- })(CHAINFLIP_QUOTE_ERROR || (CHAINFLIP_QUOTE_ERROR = {}));
37
21
  export class ChainflipSwapHandler {
38
22
  constructor(chainService, balanceService, feeService, isTestnet = true) {
39
23
  this.swapBaseHandler = new SwapBaseHandler({
@@ -45,9 +29,7 @@ export class ChainflipSwapHandler {
45
29
  });
46
30
  this.isTestnet = isTestnet;
47
31
  this.providerSlug = isTestnet ? SwapProviderId.CHAIN_FLIP_TESTNET : SwapProviderId.CHAIN_FLIP_MAINNET;
48
-
49
- // @ts-ignore
50
- this.swapSdk = new SwapSDK(getChainflipOptions(isTestnet));
32
+ this.baseUrl = getChainflipSwap(isTestnet);
51
33
  }
52
34
  get chainService() {
53
35
  return this.swapBaseHandler.chainService;
@@ -64,20 +46,6 @@ export class ChainflipSwapHandler {
64
46
  get slug() {
65
47
  return this.swapBaseHandler.slug;
66
48
  }
67
- get assetMapping() {
68
- if (this.isTestnet) {
69
- return CHAIN_FLIP_SUPPORTED_TESTNET_ASSET_MAPPING;
70
- } else {
71
- return CHAIN_FLIP_SUPPORTED_MAINNET_ASSET_MAPPING;
72
- }
73
- }
74
- get chainMapping() {
75
- if (this.isTestnet) {
76
- return CHAIN_FLIP_SUPPORTED_TESTNET_MAPPING;
77
- } else {
78
- return CHAIN_FLIP_SUPPORTED_MAINNET_MAPPING;
79
- }
80
- }
81
49
  get intermediaryAssetSlug() {
82
50
  if (this.isTestnet) {
83
51
  return INTERMEDIARY_TESTNET_ASSET_SLUG;
@@ -85,224 +53,6 @@ export class ChainflipSwapHandler {
85
53
  return INTERMEDIARY_MAINNET_ASSET_SLUG;
86
54
  }
87
55
  }
88
- async validateSwapRequest(request) {
89
- try {
90
- // todo: risk of matching wrong chain, asset can lead to loss of funds
91
-
92
- const fromAsset = this.chainService.getAssetBySlug(request.pair.from);
93
- const toAsset = this.chainService.getAssetBySlug(request.pair.to);
94
- const srcChain = fromAsset.originChain;
95
- const destChain = toAsset.originChain;
96
- const isSwapCrossChain = srcChain !== destChain;
97
- const srcChainInfo = this.chainService.getChainInfoByKey(srcChain);
98
- const srcChainId = this.chainMapping[srcChain];
99
- const destChainId = this.chainMapping[destChain];
100
- const fromAssetId = _getAssetSymbol(fromAsset);
101
- const toAssetId = _getAssetSymbol(toAsset);
102
- if (!srcChainId || !destChainId || !fromAssetId || !toAssetId) {
103
- return {
104
- error: SwapErrorType.ASSET_NOT_SUPPORTED
105
- };
106
- }
107
- const [supportedDestChains, srcAssets, destAssets] = await Promise.all([this.swapSdk.getChains(srcChainId), this.swapSdk.getAssets(srcChainId), this.swapSdk.getAssets(destChainId)]);
108
- const supportedDestChainId = supportedDestChains.find(c => c.chain === destChainId);
109
- const srcAssetData = srcAssets.find(a => {
110
- if (_isSmartContractToken(fromAsset)) {
111
- var _a$contractAddress;
112
- return (a === null || a === void 0 ? void 0 : (_a$contractAddress = a.contractAddress) === null || _a$contractAddress === void 0 ? void 0 : _a$contractAddress.toLowerCase()) === _getContractAddressOfToken(fromAsset).toLowerCase() && a.asset === fromAssetId;
113
- }
114
- return a.asset === fromAssetId;
115
- });
116
- const destAssetData = destAssets.find(a => {
117
- if (_isSmartContractToken(toAsset)) {
118
- var _a$contractAddress2;
119
- return (a === null || a === void 0 ? void 0 : (_a$contractAddress2 = a.contractAddress) === null || _a$contractAddress2 === void 0 ? void 0 : _a$contractAddress2.toLowerCase()) === _getContractAddressOfToken(toAsset).toLowerCase() && a.asset === toAssetId;
120
- }
121
- return a.asset === toAssetId;
122
- });
123
- if (!destAssetData || !srcAssetData || isSwapCrossChain && !supportedDestChainId) {
124
- return {
125
- error: SwapErrorType.UNKNOWN
126
- };
127
- }
128
- const bnAmount = new BigNumber(request.fromAmount);
129
- const bnMinSwap = new BigNumber(srcAssetData.minimumSwapAmount);
130
- if (srcAssetData.maximumSwapAmount) {
131
- const bnMaxProtocolSwap = new BigNumber(srcAssetData.maximumSwapAmount);
132
- if (bnMinSwap.gte(bnMaxProtocolSwap)) {
133
- return {
134
- error: SwapErrorType.UNKNOWN
135
- };
136
- }
137
- if (bnAmount.gte(bnMaxProtocolSwap)) {
138
- return {
139
- error: SwapErrorType.SWAP_EXCEED_ALLOWANCE,
140
- metadata: {
141
- minSwap: {
142
- value: srcAssetData.minimumSwapAmount,
143
- decimals: _getAssetDecimals(fromAsset),
144
- symbol: fromAsset.symbol
145
- },
146
- maxSwap: {
147
- value: bnMaxProtocolSwap.toString(),
148
- decimals: _getAssetDecimals(fromAsset),
149
- symbol: fromAsset.symbol
150
- },
151
- chain: srcChainInfo
152
- }
153
- };
154
- }
155
- }
156
- if (bnAmount.lt(bnMinSwap)) {
157
- // might miss case when minSwap is 0
158
- return {
159
- error: SwapErrorType.NOT_MEET_MIN_SWAP,
160
- metadata: {
161
- minSwap: {
162
- value: srcAssetData.minimumSwapAmount,
163
- decimals: _getAssetDecimals(fromAsset),
164
- symbol: fromAsset.symbol
165
- },
166
- maxSwap: {
167
- value: srcAssetData.maximumSwapAmount,
168
- decimals: _getAssetDecimals(fromAsset),
169
- symbol: fromAsset.symbol
170
- },
171
- chain: srcChainInfo
172
- }
173
- };
174
- }
175
- return {
176
- metadata: {
177
- minSwap: {
178
- value: srcAssetData.minimumSwapAmount,
179
- decimals: _getAssetDecimals(fromAsset),
180
- symbol: fromAsset.symbol
181
- },
182
- maxSwap: {
183
- value: srcAssetData.maximumSwapAmount,
184
- decimals: _getAssetDecimals(fromAsset),
185
- symbol: fromAsset.symbol
186
- },
187
- chain: srcChainInfo
188
- }
189
- };
190
- } catch (e) {
191
- return {
192
- error: SwapErrorType.UNKNOWN
193
- };
194
- }
195
- }
196
- parseSwapPath(fromAsset, toAsset) {
197
- if (toAsset.slug !== this.intermediaryAssetSlug && fromAsset.slug !== this.intermediaryAssetSlug) {
198
- // Chainflip always use USDC as intermediary
199
- return [fromAsset.slug, this.intermediaryAssetSlug, toAsset.slug]; // todo: generalize this
200
- }
201
-
202
- return [fromAsset.slug, toAsset.slug];
203
- }
204
- async getSwapQuote(request) {
205
- const fromAsset = this.chainService.getAssetBySlug(request.pair.from);
206
- const toAsset = this.chainService.getAssetBySlug(request.pair.to);
207
- const fromChain = this.chainService.getChainInfoByKey(fromAsset.originChain);
208
- const fromChainNativeTokenSlug = _getChainNativeTokenSlug(fromChain);
209
- if (!fromAsset || !toAsset) {
210
- return new SwapError(SwapErrorType.UNKNOWN);
211
- }
212
- const earlyValidation = await this.validateSwapRequest(request);
213
- const metadata = earlyValidation.metadata;
214
- if (earlyValidation.error) {
215
- return _getChainflipEarlyValidationError(earlyValidation.error, metadata);
216
- }
217
- const srcChainId = this.chainMapping[fromAsset.originChain];
218
- const destChainId = this.chainMapping[toAsset.originChain];
219
- const fromAssetId = _getAssetSymbol(fromAsset);
220
- const toAssetId = _getAssetSymbol(toAsset);
221
- try {
222
- var _metadata$maxSwap;
223
- const quoteResponse = await this.swapSdk.getQuote({
224
- srcChain: srcChainId,
225
- destChain: destChainId,
226
- srcAsset: fromAssetId,
227
- destAsset: toAssetId,
228
- amount: request.fromAmount
229
- });
230
- const feeComponent = [];
231
- quoteResponse.quote.includedFees.forEach(fee => {
232
- switch (fee.type) {
233
- case ChainflipFeeType.INGRESS:
234
- {
235
- feeComponent.push({
236
- tokenSlug: fromAsset.slug,
237
- amount: fee.amount,
238
- feeType: SwapFeeType.NETWORK_FEE
239
- });
240
- break;
241
- }
242
-
243
- // eslint-disable-next-line no-fallthrough
244
- case ChainflipFeeType.EGRESS:
245
- {
246
- feeComponent.push({
247
- tokenSlug: toAsset.slug,
248
- amount: fee.amount,
249
- feeType: SwapFeeType.NETWORK_FEE
250
- });
251
- break;
252
- }
253
- case ChainflipFeeType.NETWORK:
254
-
255
- // eslint-disable-next-line no-fallthrough
256
- case ChainflipFeeType.BOOST:
257
-
258
- // eslint-disable-next-line no-fallthrough
259
- case ChainflipFeeType.BROKER:
260
- {
261
- feeComponent.push({
262
- tokenSlug: this.intermediaryAssetSlug,
263
- amount: fee.amount,
264
- feeType: SwapFeeType.PLATFORM_FEE
265
- });
266
- break;
267
- }
268
- }
269
- });
270
- const defaultFeeToken = _isNativeToken(fromAsset) ? fromAsset.slug : fromChainNativeTokenSlug;
271
- return {
272
- pair: request.pair,
273
- fromAmount: request.fromAmount,
274
- toAmount: quoteResponse.quote.egressAmount.toString(),
275
- rate: calculateSwapRate(request.fromAmount, quoteResponse.quote.egressAmount.toString(), fromAsset, toAsset),
276
- provider: this.providerInfo,
277
- aliveUntil: +Date.now() + (SWAP_QUOTE_TIMEOUT_MAP[this.slug] || SWAP_QUOTE_TIMEOUT_MAP.default),
278
- minSwap: metadata.minSwap.value,
279
- maxSwap: (_metadata$maxSwap = metadata.maxSwap) === null || _metadata$maxSwap === void 0 ? void 0 : _metadata$maxSwap.value,
280
- estimatedArrivalTime: quoteResponse.quote.estimatedDurationSeconds,
281
- // in seconds
282
- isLowLiquidity: quoteResponse.quote.lowLiquidityWarning,
283
- feeInfo: {
284
- feeComponent: feeComponent,
285
- defaultFeeToken,
286
- feeOptions: [defaultFeeToken]
287
- },
288
- route: {
289
- path: this.parseSwapPath(fromAsset, toAsset)
290
- }
291
- };
292
- } catch (e) {
293
- var _error$response;
294
- const error = e;
295
- const errorObj = error === null || error === void 0 ? void 0 : (_error$response = error.response) === null || _error$response === void 0 ? void 0 : _error$response.data;
296
- if (errorObj && errorObj.error && errorObj.error.includes(CHAINFLIP_QUOTE_ERROR.InsufficientLiquidity)) {
297
- // todo: Chainflip will improve this
298
- return new SwapError(SwapErrorType.NOT_ENOUGH_LIQUIDITY);
299
- }
300
- if (errorObj && errorObj.message && errorObj.message.includes(CHAINFLIP_QUOTE_ERROR.InsufficientLiquidity)) {
301
- return new SwapError(SwapErrorType.NOT_ENOUGH_LIQUIDITY);
302
- }
303
- return new SwapError(SwapErrorType.ERROR_FETCHING_QUOTE);
304
- }
305
- }
306
56
  async validateSwapProcess(params) {
307
57
  const amount = params.selectedQuote.fromAmount;
308
58
  const bnAmount = new BigNumber(amount);
@@ -341,48 +91,49 @@ export class ChainflipSwapHandler {
341
91
  const fromAsset = this.chainService.getAssetBySlug(pair.from);
342
92
  const toAsset = this.chainService.getAssetBySlug(pair.to);
343
93
  const chainInfo = this.chainService.getChainInfoByKey(fromAsset.originChain);
94
+ const toChainInfo = this.chainService.getChainInfoByKey(fromAsset.originChain);
344
95
  const chainType = _isChainSubstrateCompatible(chainInfo) ? ChainType.SUBSTRATE : ChainType.EVM;
345
- const receiver = recipient !== null && recipient !== void 0 ? recipient : address;
346
- const srcChainId = this.chainMapping[fromAsset.originChain];
347
- const destChainId = this.chainMapping[toAsset.originChain];
96
+ const receiver = _reformatAddressWithChain(recipient !== null && recipient !== void 0 ? recipient : address, toChainInfo);
348
97
  const fromAssetId = _getAssetSymbol(fromAsset);
349
98
  const toAssetId = _getAssetSymbol(toAsset);
350
99
  const minReceive = new BigNumber(quote.rate).times(1 - slippage).toString();
351
- const depositAddressResponse = await this.swapSdk.requestDepositAddress({
352
- srcChain: srcChainId,
353
- destChain: destChainId,
354
- srcAsset: fromAssetId,
355
- destAsset: toAssetId,
356
- destAddress: receiver,
357
- amount: quote.fromAmount,
358
- fillOrKillParams: {
359
- minPrice: minReceive,
360
- // minimum accepted price for swaps through the channel
361
- refundAddress: address,
362
- // address to which assets are refunded
363
- retryDurationBlocks: 100 // 100 blocks * 6 seconds = 10 minutes before deposits are refunded
364
- }
100
+ const depositParams = {
101
+ destinationAddress: receiver,
102
+ destinationAsset: toAssetId,
103
+ minimumPrice: minReceive,
104
+ // minimum accepted price for swaps through the channel
105
+ refundAddress: address,
106
+ // address to which assets are refunded
107
+ retryDurationInBlocks: '100',
108
+ // 100 blocks * 6 seconds = 10 minutes before deposits are refunded
109
+ sourceAsset: fromAssetId
110
+ };
111
+ const url = `${this.baseUrl}&${new URLSearchParams(depositParams).toString()}`;
112
+ const response = await fetch(url, {
113
+ method: 'GET'
365
114
  });
366
-
115
+ const data = await response.json();
116
+ const depositChannelId = `${data.issuedBlock}-${data.network}-${data.channelId}`;
117
+ const depositAddress = data.address;
367
118
  const txData = {
368
119
  address,
369
120
  provider: this.providerInfo,
370
121
  quote: params.quote,
371
122
  slippage: params.slippage,
372
123
  recipient,
373
- depositChannelId: depositAddressResponse.depositChannelId,
374
- depositAddress: depositAddressResponse.depositAddress,
124
+ depositChannelId: depositChannelId,
125
+ depositAddress: depositAddress,
375
126
  process: params.process
376
127
  };
377
128
  let extrinsic;
378
129
  if (chainType === ChainType.SUBSTRATE) {
379
130
  const chainApi = this.chainService.getSubstrateApi(chainInfo.slug);
380
131
  const substrateApi = await chainApi.isReady;
381
- const [submittableExtrinsic] = await createTransferExtrinsic({
132
+ const [submittableExtrinsic] = await createSubstrateExtrinsic({
382
133
  from: address,
383
134
  networkKey: chainInfo.slug,
384
135
  substrateApi,
385
- to: depositAddressResponse.depositAddress,
136
+ to: depositAddress,
386
137
  tokenInfo: fromAsset,
387
138
  transferAll: false,
388
139
  // always false, because we do not allow swapping all the balance
@@ -397,7 +148,7 @@ export class ChainflipSwapHandler {
397
148
  chain: chainInfo.slug,
398
149
  evmApi: this.chainService.getEvmApi(chainInfo.slug),
399
150
  from: address,
400
- to: depositAddressResponse.depositAddress,
151
+ to: depositAddress,
401
152
  value: quote.fromAmount,
402
153
  feeInfo,
403
154
  transferAll: false
@@ -409,7 +160,7 @@ export class ChainflipSwapHandler {
409
160
  chain: chainInfo.slug,
410
161
  evmApi: this.chainService.getEvmApi(chainInfo.slug),
411
162
  from: address,
412
- to: depositAddressResponse.depositAddress,
163
+ to: depositAddress,
413
164
  value: quote.fromAmount,
414
165
  feeInfo,
415
166
  transferAll: false
@@ -1,11 +1,10 @@
1
- import { SwapError } from '@subwallet/extension-base/background/errors/SwapError';
2
1
  import { TransactionError } from '@subwallet/extension-base/background/errors/TransactionError';
3
2
  import { BalanceService } from '@subwallet/extension-base/services/balance-service';
4
3
  import { ChainService } from '@subwallet/extension-base/services/chain-service';
5
4
  import FeeService from '@subwallet/extension-base/services/fee-service/service';
6
5
  import { SwapBaseInterface } from '@subwallet/extension-base/services/swap-service/handler/base-handler';
7
6
  import { BaseStepDetail, CommonOptimalPath, CommonStepFeeInfo } from '@subwallet/extension-base/types/service-base';
8
- import { OptimalSwapPathParams, SwapEarlyValidation, SwapProviderId, SwapQuote, SwapRequest, SwapSubmitParams, SwapSubmitStepData, ValidateSwapProcessParams } from '@subwallet/extension-base/types/swap';
7
+ import { OptimalSwapPathParams, SwapProviderId, SwapSubmitParams, SwapSubmitStepData, ValidateSwapProcessParams } from '@subwallet/extension-base/types/swap';
9
8
  export declare class HydradxHandler implements SwapBaseInterface {
10
9
  private swapBaseHandler;
11
10
  private tradeRouter;
@@ -24,15 +23,11 @@ export declare class HydradxHandler implements SwapBaseInterface {
24
23
  getFeeOptionStep(params: OptimalSwapPathParams): Promise<[BaseStepDetail, CommonStepFeeInfo] | undefined>;
25
24
  getSubmitStep(params: OptimalSwapPathParams): Promise<[BaseStepDetail, CommonStepFeeInfo] | undefined>;
26
25
  generateOptimalProcess(params: OptimalSwapPathParams): Promise<CommonOptimalPath>;
27
- private getSwapPathErrors;
28
- private parseSwapPath;
29
- getSwapQuote(request: SwapRequest): Promise<SwapQuote | SwapError>;
30
26
  handleXcmStep(params: SwapSubmitParams): Promise<SwapSubmitStepData>;
31
27
  handleSetFeeStep(params: SwapSubmitParams): Promise<SwapSubmitStepData>;
32
28
  handleSubmitStep(params: SwapSubmitParams): Promise<SwapSubmitStepData>;
33
29
  handleSwapProcess(params: SwapSubmitParams): Promise<SwapSubmitStepData>;
34
30
  validateSwapProcess(params: ValidateSwapProcessParams): Promise<TransactionError[]>;
35
- validateSwapRequest(request: SwapRequest): Promise<SwapEarlyValidation>;
36
31
  get referralCode(): "WALLET" | "ASSETHUB";
37
32
  get referralAccount(): "7PCsCpkgsHdNaZhv79wCCQ5z97uxVbSeSCtDMUa1eZHKXy4a" | "7LCt6dFqtxzdKVB2648jWW9d85doiFfLSbZJDNAMVJNxh5rJ";
38
33
  }
@@ -1,24 +1,21 @@
1
1
  // Copyright 2019-2022 @subwallet/extension-base
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- import { PoolError, PoolService, TradeRouter } from '@galacticcouncil/sdk';
4
+ import { PoolService, TradeRouter } from '@galacticcouncil/sdk';
5
5
  import { COMMON_CHAIN_SLUGS } from '@subwallet/chain-list';
6
- import { _AssetType } from '@subwallet/chain-list/types';
7
6
  import { SwapError } from '@subwallet/extension-base/background/errors/SwapError';
8
7
  import { TransactionError } from '@subwallet/extension-base/background/errors/TransactionError';
9
8
  import { ChainType, ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
10
9
  import { XCM_MIN_AMOUNT_RATIO } from '@subwallet/extension-base/constants';
11
- import { _getEarlyHydradxValidationError } from '@subwallet/extension-base/core/logic-validation/swap';
12
10
  import { createXcmExtrinsic } from '@subwallet/extension-base/services/balance-service/transfer/xcm';
13
11
  import { _getAssetDecimals, _getChainNativeTokenSlug, _getTokenOnChainAssetId, _isNativeToken } from '@subwallet/extension-base/services/chain-service/utils';
14
12
  import { SwapBaseHandler } from '@subwallet/extension-base/services/swap-service/handler/base-handler';
15
- import { calculateSwapRate, getSwapAlternativeAsset, SWAP_QUOTE_TIMEOUT_MAP } from '@subwallet/extension-base/services/swap-service/utils';
13
+ import { getSwapAlternativeAsset } from '@subwallet/extension-base/services/swap-service/utils';
16
14
  import { BasicTxErrorType } from '@subwallet/extension-base/types';
17
15
  import { CommonStepType } from '@subwallet/extension-base/types/service-base';
18
16
  import { SwapErrorType, SwapFeeType, SwapProviderId, SwapStepType } from '@subwallet/extension-base/types/swap';
19
17
  import { getId } from '@subwallet/extension-base/utils/getId';
20
18
  import BigNumber from 'bignumber.js';
21
- const HYDRADX_LOW_LIQUIDITY_THRESHOLD = 0.15;
22
19
  const HYDRADX_SUBWALLET_REFERRAL_CODE = 'WALLET';
23
20
  const HYDRADX_SUBWALLET_REFERRAL_ACCOUNT = '7PCsCpkgsHdNaZhv79wCCQ5z97uxVbSeSCtDMUa1eZHKXy4a';
24
21
  const HYDRADX_TESTNET_SUBWALLET_REFERRAL_CODE = 'ASSETHUB';
@@ -195,120 +192,6 @@ export class HydradxHandler {
195
192
  // this.getFeeOptionStep.bind(this),
196
193
  this.getSubmitStep.bind(this)]);
197
194
  }
198
- getSwapPathErrors(swapList) {
199
- return swapList.reduce((prev, current) => {
200
- return [...prev, ...current.errors];
201
- }, []);
202
- }
203
- parseSwapPath(swapList) {
204
- const swapAssets = this.chainService.getAssetByChainAndType(this.chain(), [_AssetType.NATIVE, _AssetType.LOCAL]);
205
- const swapAssetIdMap = Object.values(swapAssets).reduce((accumulator, asset) => {
206
- return {
207
- ...accumulator,
208
- [_getTokenOnChainAssetId(asset)]: asset
209
- };
210
- }, {});
211
- const path = [];
212
- swapList.forEach(swap => {
213
- var _swapAssetIdMap$swap$, _swapAssetIdMap$swap$2;
214
- const swapAssetIn = (_swapAssetIdMap$swap$ = swapAssetIdMap[swap.assetIn]) === null || _swapAssetIdMap$swap$ === void 0 ? void 0 : _swapAssetIdMap$swap$.slug;
215
- const swapAssetOut = (_swapAssetIdMap$swap$2 = swapAssetIdMap[swap.assetOut]) === null || _swapAssetIdMap$swap$2 === void 0 ? void 0 : _swapAssetIdMap$swap$2.slug;
216
- if (swapAssetIn && !path.includes(swapAssetIn)) {
217
- path.push(swapAssetIn);
218
- }
219
- if (swapAssetOut && !path.includes(swapAssetOut)) {
220
- path.push(swapAssetOut);
221
- }
222
- });
223
- return {
224
- path
225
- };
226
- }
227
- async getSwapQuote(request) {
228
- const fromAsset = this.chainService.getAssetBySlug(request.pair.from);
229
- const toAsset = this.chainService.getAssetBySlug(request.pair.to);
230
- const fromChain = this.chainService.getChainInfoByKey(fromAsset.originChain);
231
- const fromChainNativeTokenSlug = _getChainNativeTokenSlug(fromChain);
232
- if (!this.isReady || !this.tradeRouter) {
233
- return new SwapError(SwapErrorType.UNKNOWN);
234
- }
235
- const earlyValidation = await this.validateSwapRequest(request);
236
- if (earlyValidation.error) {
237
- const metadata = earlyValidation.metadata;
238
- return _getEarlyHydradxValidationError(earlyValidation.error, metadata);
239
- }
240
- try {
241
- const fromAssetId = _getTokenOnChainAssetId(fromAsset);
242
- const toAssetId = _getTokenOnChainAssetId(toAsset);
243
- const parsedFromAmount = new BigNumber(request.fromAmount).shiftedBy(-1 * _getAssetDecimals(fromAsset)).toString();
244
- const quoteResponse = await this.tradeRouter.getBestSell(fromAssetId, toAssetId, parsedFromAmount);
245
- const toAmount = quoteResponse.amountOut;
246
- const minReceive = toAmount.times(1 - request.slippage).integerValue();
247
- const txHex = quoteResponse.toTx(minReceive).hex;
248
- const substrateApi = this.chainService.getSubstrateApi(this.chain());
249
- const extrinsic = substrateApi.api.tx(txHex);
250
- const paymentInfo = await extrinsic.paymentInfo(request.address);
251
- const networkFee = {
252
- tokenSlug: fromChainNativeTokenSlug,
253
- amount: paymentInfo.partialFee.toString(),
254
- feeType: SwapFeeType.NETWORK_FEE
255
- };
256
- const tradeFee = {
257
- tokenSlug: toAsset.slug,
258
- // fee is subtracted from receiving amount
259
- amount: quoteResponse.tradeFee.toString(),
260
- feeType: SwapFeeType.PLATFORM_FEE
261
- };
262
- const swapRoute = this.parseSwapPath(quoteResponse.swaps);
263
- const swapPathErrors = this.getSwapPathErrors(quoteResponse.swaps);
264
- if (swapPathErrors.length > 0) {
265
- const defaultError = swapPathErrors[0]; // might parse more errors
266
-
267
- switch (defaultError) {
268
- case PoolError.InsufficientTradingAmount:
269
- return new SwapError(SwapErrorType.NOT_MEET_MIN_SWAP);
270
- case PoolError.TradeNotAllowed:
271
- return new SwapError(SwapErrorType.ERROR_FETCHING_QUOTE);
272
- case PoolError.MaxInRatioExceeded:
273
- return new SwapError(SwapErrorType.NOT_ENOUGH_LIQUIDITY);
274
- case PoolError.UnknownError:
275
- return new SwapError(SwapErrorType.ERROR_FETCHING_QUOTE);
276
- case PoolError.MaxOutRatioExceeded:
277
- return new SwapError(SwapErrorType.NOT_ENOUGH_LIQUIDITY);
278
- }
279
- }
280
-
281
- // const feeTokenOptions = this.chainService.getFeeTokensByChain(this.chain());
282
- const feeTokenOptions = [fromChainNativeTokenSlug];
283
-
284
- // if (request.feeToken && !feeTokenOptions.includes(request.feeToken)) {
285
- // return new SwapError(SwapErrorType.UNKNOWN);
286
- // }
287
-
288
- // const selectedFeeToken = request.feeToken || fromChainNativeTokenSlug;
289
- const selectedFeeToken = fromChainNativeTokenSlug;
290
- return {
291
- pair: request.pair,
292
- fromAmount: request.fromAmount,
293
- toAmount: toAmount.toString(),
294
- rate: calculateSwapRate(request.fromAmount, toAmount.toString(), fromAsset, toAsset),
295
- provider: this.providerInfo,
296
- aliveUntil: +Date.now() + (SWAP_QUOTE_TIMEOUT_MAP[this.slug] || SWAP_QUOTE_TIMEOUT_MAP.default),
297
- feeInfo: {
298
- feeComponent: [networkFee, tradeFee],
299
- defaultFeeToken: fromChainNativeTokenSlug,
300
- feeOptions: feeTokenOptions,
301
- // TODO: enable fee options
302
- selectedFeeToken
303
- },
304
- isLowLiquidity: Math.abs(quoteResponse.priceImpactPct) >= HYDRADX_LOW_LIQUIDITY_THRESHOLD,
305
- route: swapRoute,
306
- metadata: txHex
307
- };
308
- } catch (e) {
309
- return new SwapError(SwapErrorType.ERROR_FETCHING_QUOTE);
310
- }
311
- }
312
195
  async handleXcmStep(params) {
313
196
  const pair = params.quote.pair;
314
197
  const alternativeAssetSlug = getSwapAlternativeAsset(pair);
@@ -383,8 +266,18 @@ export class HydradxHandler {
383
266
  };
384
267
  }
385
268
  async handleSubmitStep(params) {
386
- const txHex = params.quote.metadata;
387
269
  const fromAsset = this.chainService.getAssetBySlug(params.quote.pair.from);
270
+ const toAsset = this.chainService.getAssetBySlug(params.quote.pair.to);
271
+ const fromAssetId = _getTokenOnChainAssetId(fromAsset);
272
+ const toAssetId = _getTokenOnChainAssetId(toAsset);
273
+ if (!this.isReady || !this.tradeRouter) {
274
+ return new SwapError(SwapErrorType.UNKNOWN);
275
+ }
276
+ const parsedFromAmount = new BigNumber(params.quote.fromAmount).shiftedBy(-1 * _getAssetDecimals(fromAsset)).toString();
277
+ const quoteResponse = await this.tradeRouter.getBestSell(fromAssetId, toAssetId, parsedFromAmount);
278
+ const toAmount = quoteResponse.amountOut;
279
+ const minReceive = toAmount.times(1 - params.slippage).integerValue();
280
+ const txHex = quoteResponse.toTx(minReceive).hex;
388
281
  const substrateApi = this.chainService.getSubstrateApi(this.chain());
389
282
  const chainApi = await substrateApi.isReady;
390
283
  const txData = {
@@ -474,66 +367,6 @@ export class HydradxHandler {
474
367
  }
475
368
  return [];
476
369
  }
477
- async validateSwapRequest(request) {
478
- const fromAsset = this.chainService.getAssetBySlug(request.pair.from);
479
- const toAsset = this.chainService.getAssetBySlug(request.pair.to);
480
- const fromAssetId = _getTokenOnChainAssetId(fromAsset);
481
- const toAssetId = _getTokenOnChainAssetId(toAsset);
482
- try {
483
- var _this$tradeRouter, _this$tradeRouter2;
484
- // todo: might need to optimize for performance, but prioritize safety for now
485
- const allAssets = await ((_this$tradeRouter = this.tradeRouter) === null || _this$tradeRouter === void 0 ? void 0 : _this$tradeRouter.getAllAssets());
486
- if (!allAssets) {
487
- return {
488
- error: SwapErrorType.UNKNOWN
489
- };
490
- }
491
- const supportedFromAsset = allAssets.find(asset => asset.id === fromAssetId && asset.symbol === fromAsset.symbol);
492
- const supportedToAsset = allAssets.find(asset => asset.id === toAssetId && asset.symbol === toAsset.symbol);
493
- if (!supportedFromAsset || !supportedToAsset) {
494
- return {
495
- error: SwapErrorType.ASSET_NOT_SUPPORTED
496
- };
497
- }
498
- const assetPairs = await ((_this$tradeRouter2 = this.tradeRouter) === null || _this$tradeRouter2 === void 0 ? void 0 : _this$tradeRouter2.getAssetPairs(fromAssetId));
499
- if (!assetPairs) {
500
- return {
501
- error: SwapErrorType.UNKNOWN
502
- };
503
- }
504
- const pairedToAsset = assetPairs.find(supportedToAsset => supportedToAsset.id === toAssetId && supportedToAsset.symbol === toAsset.symbol);
505
- if (!pairedToAsset) {
506
- return {
507
- error: SwapErrorType.ASSET_NOT_SUPPORTED
508
- };
509
- }
510
- if (!(fromAsset.originChain === this.chain() && toAsset.originChain === this.chain())) {
511
- return {
512
- error: SwapErrorType.ASSET_NOT_SUPPORTED
513
- };
514
- }
515
- if (!fromAssetId || !toAssetId) {
516
- return {
517
- error: SwapErrorType.UNKNOWN
518
- };
519
- }
520
- const bnAmount = new BigNumber(request.fromAmount);
521
- if (bnAmount.lte(0)) {
522
- return {
523
- error: SwapErrorType.AMOUNT_CANNOT_BE_ZERO
524
- };
525
- }
526
- return {
527
- metadata: {
528
- chain: this.chainService.getChainInfoByKey(this.chain())
529
- }
530
- };
531
- } catch (e) {
532
- return {
533
- error: SwapErrorType.UNKNOWN
534
- };
535
- }
536
- }
537
370
  get referralCode() {
538
371
  if (this.isTestnet) {
539
372
  return HYDRADX_TESTNET_SUBWALLET_REFERRAL_CODE;
@@ -1,7 +1,6 @@
1
- import { SwapError } from '@subwallet/extension-base/background/errors/SwapError';
2
1
  import { TransactionError } from '@subwallet/extension-base/background/errors/TransactionError';
3
2
  import FeeService from '@subwallet/extension-base/services/fee-service/service';
4
- import { BaseStepDetail, CommonOptimalPath, CommonStepFeeInfo, OptimalSwapPathParams, SwapEarlyValidation, SwapProviderId, SwapQuote, SwapRequest, SwapSubmitParams, SwapSubmitStepData, ValidateSwapProcessParams } from '@subwallet/extension-base/types';
3
+ import { BaseStepDetail, CommonOptimalPath, CommonStepFeeInfo, OptimalSwapPathParams, SwapProviderId, SwapSubmitParams, SwapSubmitStepData, ValidateSwapProcessParams } from '@subwallet/extension-base/types';
5
4
  import { BalanceService } from '../../balance-service';
6
5
  import { ChainService } from '../../chain-service';
7
6
  import { SwapBaseInterface } from './base-handler';
@@ -16,10 +15,8 @@ export declare class SimpleSwapHandler implements SwapBaseInterface {
16
15
  get providerInfo(): import("@subwallet/extension-base/types").SwapProvider;
17
16
  get name(): string;
18
17
  get slug(): string;
19
- getSwapQuote(request: SwapRequest): Promise<SwapQuote | SwapError>;
20
18
  generateOptimalProcess(params: OptimalSwapPathParams): Promise<CommonOptimalPath>;
21
19
  getSubmitStep(params: OptimalSwapPathParams): Promise<[BaseStepDetail, CommonStepFeeInfo] | undefined>;
22
- validateSwapRequest(request: SwapRequest): Promise<SwapEarlyValidation>;
23
20
  handleSwapProcess(params: SwapSubmitParams): Promise<SwapSubmitStepData>;
24
21
  handleSubmitStep(params: SwapSubmitParams): Promise<SwapSubmitStepData>;
25
22
  }