@subwallet/extension-base 1.0.1 → 1.0.2-1b

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 (220) hide show
  1. package/background/KoniTypes.d.ts +25 -36
  2. package/background/KoniTypes.js +12 -7
  3. package/background/errors/TransactionError.js +21 -1
  4. package/cjs/background/KoniTypes.js +14 -8
  5. package/cjs/background/errors/TransactionError.js +20 -0
  6. package/cjs/constants/index.js +13 -28
  7. package/cjs/koni/api/dotsama/balance.js +60 -224
  8. package/cjs/koni/api/dotsama/transfer.js +30 -29
  9. package/cjs/koni/api/nft/acala_nft/index.js +4 -1
  10. package/cjs/koni/api/nft/bit.country/index.js +4 -1
  11. package/cjs/koni/api/nft/evm_nft/index.js +7 -3
  12. package/cjs/koni/api/nft/index.js +3 -6
  13. package/cjs/koni/api/nft/karura_nft/index.js +4 -1
  14. package/cjs/koni/api/nft/rmrk_nft/index.js +8 -1
  15. package/cjs/koni/api/nft/statemine_nft/index.js +4 -1
  16. package/cjs/koni/api/nft/unique_nft/index.js +6 -1
  17. package/cjs/koni/api/nft/wasm_nft/index.js +169 -111
  18. package/cjs/koni/api/nft/wasm_nft/utils.js +11 -7
  19. package/cjs/koni/api/staking/bonding/amplitude.js +18 -10
  20. package/cjs/koni/api/staking/bonding/astar.js +37 -238
  21. package/cjs/koni/api/staking/bonding/index.js +26 -14
  22. package/cjs/koni/api/staking/bonding/paraChain.js +100 -11
  23. package/cjs/koni/api/staking/bonding/relayChain.js +174 -16
  24. package/cjs/koni/api/staking/bonding/utils.js +55 -10
  25. package/cjs/koni/api/tokens/wasm/index.js +5 -4
  26. package/cjs/koni/api/tokens/wasm/utils.js +63 -0
  27. package/cjs/koni/api/xcm/index.js +0 -111
  28. package/cjs/koni/api/xcm/polkadotXcm.js +2 -2
  29. package/cjs/koni/api/xcm/utils.js +18 -13
  30. package/cjs/koni/api/xcm/xTokens.js +3 -5
  31. package/cjs/koni/api/xcm/xcmPallet.js +9 -6
  32. package/cjs/koni/background/cron.js +179 -77
  33. package/cjs/koni/background/handlers/Extension.js +231 -195
  34. package/cjs/koni/background/handlers/State.js +147 -111
  35. package/cjs/koni/background/handlers/Tabs.js +48 -39
  36. package/cjs/koni/background/subscription.js +64 -56
  37. package/cjs/packageInfo.js +1 -1
  38. package/cjs/page/index.js +5 -0
  39. package/cjs/services/chain-service/constants.js +1 -11
  40. package/cjs/services/chain-service/handler/SubstrateChainHandler.js +13 -8
  41. package/cjs/services/chain-service/handler/light-client/index.js +2 -0
  42. package/cjs/services/chain-service/index.js +39 -6
  43. package/cjs/services/chain-service/utils.js +4 -0
  44. package/cjs/services/event-service/index.js +75 -0
  45. package/cjs/services/event-service/types.js +11 -0
  46. package/cjs/services/history-service/index.js +46 -21
  47. package/cjs/services/history-service/subsquid-multi-chain-history.js +19 -11
  48. package/cjs/services/keyring-service/index.js +101 -0
  49. package/cjs/services/migration-service/index.js +13 -10
  50. package/cjs/{koni/migration/scripts/RemoveWrongCrowdloan.js → services/migration-service/scripts/AutoEnableChainsTokens.js} +11 -6
  51. package/cjs/services/migration-service/scripts/MigrateNetworkSettings.js +39 -19
  52. package/cjs/services/migration-service/scripts/MigrateSettings.js +31 -0
  53. package/cjs/services/migration-service/scripts/MigrateTransactionHistory.js +72 -0
  54. package/cjs/services/migration-service/scripts/index.js +13 -4
  55. package/cjs/services/price-service/coingecko.js +15 -3
  56. package/cjs/services/price-service/index.js +15 -18
  57. package/cjs/services/request-service/constants.js +8 -2
  58. package/cjs/services/request-service/handler/AuthRequestHandler.js +43 -12
  59. package/cjs/services/request-service/index.js +3 -0
  60. package/cjs/services/storage-service/DatabaseService.js +53 -34
  61. package/cjs/services/storage-service/databases/index.js +1 -1
  62. package/cjs/services/storage-service/db-stores/BaseStoreWithAddressAndChain.js +2 -8
  63. package/cjs/services/storage-service/db-stores/Nft.js +8 -18
  64. package/cjs/services/storage-service/db-stores/Transaction.js +10 -7
  65. package/cjs/services/subscan-service/index.js +107 -0
  66. package/cjs/services/subscan-service/subscan-chain-map.js +74 -0
  67. package/cjs/services/subscan-service/types.js +1 -0
  68. package/cjs/services/transaction-service/event-parser/index.js +20 -48
  69. package/cjs/services/transaction-service/index.js +66 -22
  70. package/cjs/services/transaction-service/utils.js +4 -6
  71. package/cjs/utils/address.js +9 -1
  72. package/cjs/utils/index.js +30 -26
  73. package/constants/index.d.ts +8 -13
  74. package/constants/index.js +8 -13
  75. package/koni/api/dotsama/balance.d.ts +0 -1
  76. package/koni/api/dotsama/balance.js +33 -197
  77. package/koni/api/dotsama/transfer.js +5 -4
  78. package/koni/api/nft/acala_nft/index.js +3 -1
  79. package/koni/api/nft/bit.country/index.js +3 -1
  80. package/koni/api/nft/evm_nft/index.js +6 -3
  81. package/koni/api/nft/index.d.ts +1 -2
  82. package/koni/api/nft/index.js +3 -6
  83. package/koni/api/nft/karura_nft/index.js +3 -1
  84. package/koni/api/nft/nft.d.ts +1 -0
  85. package/koni/api/nft/rmrk_nft/index.js +8 -1
  86. package/koni/api/nft/statemine_nft/index.js +3 -1
  87. package/koni/api/nft/unique_nft/index.js +5 -1
  88. package/koni/api/nft/wasm_nft/index.d.ts +0 -2
  89. package/koni/api/nft/wasm_nft/index.js +167 -109
  90. package/koni/api/nft/wasm_nft/utils.d.ts +7 -5
  91. package/koni/api/nft/wasm_nft/utils.js +7 -5
  92. package/koni/api/staking/bonding/amplitude.d.ts +1 -2
  93. package/koni/api/staking/bonding/amplitude.js +22 -13
  94. package/koni/api/staking/bonding/astar.d.ts +2 -11
  95. package/koni/api/staking/bonding/astar.js +39 -231
  96. package/koni/api/staking/bonding/index.d.ts +5 -2
  97. package/koni/api/staking/bonding/index.js +27 -17
  98. package/koni/api/staking/bonding/paraChain.d.ts +4 -1
  99. package/koni/api/staking/bonding/paraChain.js +101 -14
  100. package/koni/api/staking/bonding/relayChain.d.ts +6 -2
  101. package/koni/api/staking/bonding/relayChain.js +172 -17
  102. package/koni/api/staking/bonding/utils.d.ts +15 -2
  103. package/koni/api/staking/bonding/utils.js +53 -11
  104. package/koni/api/tokens/wasm/index.js +5 -4
  105. package/koni/api/tokens/wasm/utils.d.ts +6 -0
  106. package/koni/api/tokens/wasm/utils.js +54 -0
  107. package/koni/api/xcm/index.js +1 -112
  108. package/koni/api/xcm/polkadotXcm.js +3 -3
  109. package/koni/api/xcm/utils.d.ts +5 -6
  110. package/koni/api/xcm/utils.js +15 -10
  111. package/koni/api/xcm/xTokens.js +5 -7
  112. package/koni/api/xcm/xcmPallet.js +10 -9
  113. package/koni/background/cron.d.ts +6 -1
  114. package/koni/background/cron.js +179 -76
  115. package/koni/background/handlers/Extension.d.ts +2 -2
  116. package/koni/background/handlers/Extension.js +161 -125
  117. package/koni/background/handlers/State.d.ts +21 -20
  118. package/koni/background/handlers/State.js +144 -111
  119. package/koni/background/handlers/Tabs.js +30 -20
  120. package/koni/background/subscription.d.ts +1 -1
  121. package/koni/background/subscription.js +64 -58
  122. package/package.json +63 -18
  123. package/packageInfo.js +1 -1
  124. package/page/index.d.ts +2 -0
  125. package/page/index.js +4 -0
  126. package/services/chain-service/constants.d.ts +0 -1
  127. package/services/chain-service/constants.js +0 -9
  128. package/services/chain-service/handler/SubstrateChainHandler.js +14 -9
  129. package/services/chain-service/handler/light-client/index.d.ts +17 -1
  130. package/services/chain-service/handler/light-client/index.js +1 -1
  131. package/services/chain-service/helper/psp22_abi.json +1041 -881
  132. package/services/chain-service/helper/psp34_abi.json +2963 -1807
  133. package/services/chain-service/index.d.ts +6 -4
  134. package/services/chain-service/index.js +40 -9
  135. package/services/chain-service/utils.d.ts +1 -0
  136. package/services/chain-service/utils.js +3 -0
  137. package/services/event-service/index.d.ts +22 -0
  138. package/services/event-service/index.js +63 -0
  139. package/services/event-service/types.d.ts +28 -0
  140. package/services/event-service/types.js +4 -0
  141. package/services/history-service/index.d.ts +5 -3
  142. package/services/history-service/index.js +46 -21
  143. package/services/history-service/subsquid-multi-chain-history.js +22 -13
  144. package/services/keyring-service/index.d.ts +19 -0
  145. package/services/keyring-service/index.js +93 -0
  146. package/services/migration-service/index.js +11 -9
  147. package/services/migration-service/scripts/AutoEnableChainsTokens.d.ts +4 -0
  148. package/services/migration-service/scripts/AutoEnableChainsTokens.js +13 -0
  149. package/services/migration-service/scripts/MigrateNetworkSettings.js +37 -18
  150. package/services/migration-service/scripts/MigrateSettings.d.ts +4 -0
  151. package/services/migration-service/scripts/MigrateSettings.js +23 -0
  152. package/services/migration-service/scripts/MigrateTransactionHistory.d.ts +4 -0
  153. package/services/migration-service/scripts/MigrateTransactionHistory.js +64 -0
  154. package/services/migration-service/scripts/index.d.ts +1 -0
  155. package/services/migration-service/scripts/index.js +10 -3
  156. package/services/price-service/coingecko.js +15 -3
  157. package/services/price-service/index.d.ts +5 -3
  158. package/services/price-service/index.js +15 -18
  159. package/services/request-service/constants.d.ts +1 -0
  160. package/services/request-service/constants.js +6 -1
  161. package/services/request-service/handler/AuthRequestHandler.d.ts +8 -1
  162. package/services/request-service/handler/AuthRequestHandler.js +44 -13
  163. package/services/request-service/index.d.ts +7 -1
  164. package/services/request-service/index.js +3 -0
  165. package/services/storage-service/DatabaseService.d.ts +1 -0
  166. package/services/storage-service/DatabaseService.js +53 -34
  167. package/services/storage-service/databases/index.js +1 -1
  168. package/services/storage-service/db-stores/BaseStoreWithAddressAndChain.d.ts +1 -1
  169. package/services/storage-service/db-stores/BaseStoreWithAddressAndChain.js +2 -8
  170. package/services/storage-service/db-stores/Nft.d.ts +3 -3
  171. package/services/storage-service/db-stores/Nft.js +8 -17
  172. package/services/storage-service/db-stores/Transaction.js +10 -7
  173. package/services/subscan-service/index.d.ts +20 -0
  174. package/services/subscan-service/index.js +99 -0
  175. package/services/subscan-service/subscan-chain-map.d.ts +5 -0
  176. package/services/subscan-service/subscan-chain-map.js +63 -0
  177. package/services/subscan-service/types.d.ts +27 -0
  178. package/services/subscan-service/types.js +1 -0
  179. package/services/transaction-service/event-parser/index.d.ts +2 -2
  180. package/services/transaction-service/event-parser/index.js +21 -49
  181. package/services/transaction-service/index.d.ts +4 -2
  182. package/services/transaction-service/index.js +66 -22
  183. package/services/transaction-service/utils.js +5 -6
  184. package/utils/address.d.ts +1 -0
  185. package/utils/address.js +9 -2
  186. package/utils/index.d.ts +2 -1
  187. package/utils/index.js +26 -23
  188. package/cjs/background/errors/EvmRpcError.js +0 -21
  189. package/cjs/background/errors/SubWalletProviderError.js +0 -17
  190. package/cjs/constants/ethereum.js +0 -19
  191. package/cjs/errors/SubWalletProviderError.js +0 -17
  192. package/cjs/koni/api/xcm/astar.js +0 -160
  193. package/cjs/koni/api/xcm/moonbeamXcm.js +0 -80
  194. package/cjs/koni/api/xcm/statemintXcm.js +0 -197
  195. package/cjs/koni/api/xcm/substrateXcm.js +0 -213
  196. package/cjs/koni/migration/Base.js +0 -20
  197. package/cjs/koni/migration/index.js +0 -45
  198. package/cjs/koni/migration/scripts/ChangeRouteToHome.js +0 -22
  199. package/cjs/koni/migration/scripts/ClearOldStorage.js +0 -24
  200. package/cjs/koni/migration/scripts/RemoveWrongTransactionHistoriesFromStore.js +0 -36
  201. package/cjs/koni/migration/scripts/ResetTransactionHistoryEventIdx.js +0 -21
  202. package/cjs/koni/migration/scripts/index.js +0 -22
  203. package/cjs/koni/page/index.js +0 -16
  204. package/cjs/services/asset-service/index.js +0 -91
  205. package/cjs/services/storage-service/db-stores/ExtraDelegationInfo.js +0 -17
  206. package/cjs/stores/Balance.js +0 -18
  207. package/cjs/stores/Crowdloan.js +0 -18
  208. package/cjs/stores/CustomEvmToken.js +0 -18
  209. package/cjs/stores/NetworkMap.js +0 -18
  210. package/cjs/stores/Nft.js +0 -18
  211. package/cjs/stores/NftCollection.js +0 -18
  212. package/cjs/stores/Price.js +0 -18
  213. package/cjs/stores/Staking.js +0 -18
  214. package/cjs/stores/StakingReward.js +0 -18
  215. package/cjs/utils/eth/parseTransactionData.js +0 -284
  216. package/koni/page/index.d.ts +0 -2
  217. package/koni/page/index.js +0 -9
  218. /package/cjs/{koni/page → page}/SubWalleEvmProvider.js +0 -0
  219. /package/{koni/page → page}/SubWalleEvmProvider.d.ts +0 -0
  220. /package/{koni/page → page}/SubWalleEvmProvider.js +0 -0
@@ -1,197 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.statemintEstimateCrossChainFee = statemintEstimateCrossChainFee;
7
- exports.statemintGetXcmExtrinsic = statemintGetXcmExtrinsic;
8
- var _utils = require("@subwallet/extension-base/koni/api/xcm/utils");
9
- var _utils2 = require("@subwallet/extension-base/services/chain-service/utils");
10
- // Copyright 2019-2022 @subwallet/extension-base
11
- // SPDX-License-Identifier: Apache-2.0
12
-
13
- // const ASSET_TO_LOCATION_MAP: Record<string, Record<string, any>> = {
14
- // statemint: {
15
- // 1984: [ // USDt
16
- // {
17
- // PalletInstance: 50
18
- // },
19
- // {
20
- // GeneralIndex: 1984
21
- // }
22
- // ]
23
- // }
24
- // };
25
-
26
- async function statemintEstimateCrossChainFee(originNetworkKey, destinationNetworkKey, recipient, sender, sendingValue, substrateApiMap, originTokenInfo, chainInfoMap) {
27
- const substrateApi = await substrateApiMap[originNetworkKey].isReady;
28
- let fee = '0';
29
- const destinationChainInfo = chainInfoMap[destinationNetworkKey];
30
- const receiverLocation = (0, _utils.getReceiverLocation)(originNetworkKey, destinationNetworkKey, chainInfoMap, recipient);
31
- try {
32
- if ((0, _utils2._isSubstrateParaChain)(destinationChainInfo)) {
33
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
34
- const assetMultilocation = (0, _utils2._getXcmAssetMultilocation)(originTokenInfo);
35
- const destinationChainLocation = {
36
- V1: {
37
- // find the destination chain
38
- parents: 1,
39
- interior: {
40
- X1: {
41
- Parachain: (0, _utils2._getSubstrateParaId)(destinationChainInfo)
42
- }
43
- }
44
- }
45
- };
46
- const extrinsic = substrateApi.api.tx.polkadotXcm.limitedReserveTransferAssets(destinationChainLocation,
47
- // dest
48
- {
49
- V1: {
50
- // beneficiary
51
- parents: 0,
52
- interior: {
53
- X1: receiverLocation
54
- }
55
- }
56
- }, {
57
- V1: [{
58
- id: {
59
- Concrete: {
60
- parents: 0,
61
- interior: {
62
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
63
- X2: assetMultilocation
64
- }
65
- }
66
- },
67
- fun: {
68
- Fungible: sendingValue
69
- }
70
- }]
71
- }, 0,
72
- // FeeAssetItem
73
- _utils.POLKADOT_UNLIMITED_WEIGHT);
74
- console.log('statemint xcm tx to p here', extrinsic.toHex());
75
- const paymentInfo = await extrinsic.paymentInfo(sender);
76
- fee = paymentInfo.partialFee.toString();
77
- } else {
78
- const extrinsic = substrateApi.api.tx.polkadotXcm.limitedTeleportAssets({
79
- V1: {
80
- parents: 1,
81
- interior: 'Here'
82
- }
83
- },
84
- // dest
85
- {
86
- V1: {
87
- // beneficiary
88
- parents: 0,
89
- interior: {
90
- X1: receiverLocation
91
- }
92
- }
93
- }, {
94
- V1: [{
95
- id: {
96
- Concrete: {
97
- parents: 1,
98
- interior: 'Here' // Native token of relaychain
99
- }
100
- },
101
-
102
- fun: {
103
- Fungible: sendingValue
104
- }
105
- }]
106
- }, 0,
107
- // FeeAssetItem
108
- _utils.POLKADOT_UNLIMITED_WEIGHT);
109
- console.log('statemint xcm tx to r here', extrinsic.toHex());
110
- const paymentInfo = await extrinsic.paymentInfo(sender);
111
- fee = paymentInfo.partialFee.toString();
112
- }
113
- return fee;
114
- } catch (e) {
115
- console.error('error parsing xcm transaction', e);
116
- return '0';
117
- }
118
- }
119
- function statemintGetXcmExtrinsic(originNetworkKey, destinationNetworkKey, recipient, sendingValue, api, originTokenInfo, chainInfoMap) {
120
- const destinationChainInfo = chainInfoMap[destinationNetworkKey];
121
- const receiverLocation = (0, _utils.getReceiverLocation)(originNetworkKey, destinationNetworkKey, chainInfoMap, recipient);
122
- if ((0, _utils2._isSubstrateParaChain)(destinationChainInfo)) {
123
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
124
- const assetLocation = (0, _utils2._getXcmAssetMultilocation)(originTokenInfo);
125
- const destinationChainLocation = {
126
- V1: {
127
- // find the destination chain
128
- parents: 1,
129
- interior: {
130
- X1: {
131
- Parachain: (0, _utils2._getSubstrateParaId)(destinationChainInfo)
132
- }
133
- }
134
- }
135
- };
136
- return api.tx.polkadotXcm.limitedReserveTransferAssets(destinationChainLocation,
137
- // dest
138
- {
139
- V1: {
140
- // beneficiary
141
- parents: 0,
142
- interior: {
143
- X1: receiverLocation
144
- }
145
- }
146
- }, {
147
- V1: [{
148
- id: {
149
- Concrete: {
150
- parents: 0,
151
- interior: {
152
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
153
- X2: assetLocation
154
- }
155
- }
156
- },
157
- fun: {
158
- Fungible: sendingValue
159
- }
160
- }]
161
- }, 0,
162
- // FeeAssetItem
163
- _utils.POLKADOT_UNLIMITED_WEIGHT);
164
- } else {
165
- return api.tx.polkadotXcm.limitedTeleportAssets({
166
- V1: {
167
- parents: 1,
168
- interior: 'Here'
169
- }
170
- },
171
- // dest
172
- {
173
- V1: {
174
- // beneficiary
175
- parents: 0,
176
- interior: {
177
- X1: receiverLocation
178
- }
179
- }
180
- }, {
181
- V1: [{
182
- id: {
183
- Concrete: {
184
- parents: 1,
185
- interior: 'Here' // Native token of relaychain
186
- }
187
- },
188
-
189
- fun: {
190
- Fungible: sendingValue
191
- }
192
- }]
193
- }, 0,
194
- // FeeAssetItem
195
- _utils.POLKADOT_UNLIMITED_WEIGHT);
196
- }
197
- }
@@ -1,213 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.substrateEstimateCrossChainFee = substrateEstimateCrossChainFee;
7
- exports.substrateGetXcmExtrinsic = substrateGetXcmExtrinsic;
8
- var _utils = require("@subwallet/extension-base/koni/api/xcm/utils");
9
- var _constants = require("@subwallet/extension-base/services/chain-service/constants");
10
- var _utils2 = require("@subwallet/extension-base/services/chain-service/utils");
11
- // Copyright 2019-2022 @subwallet/extension-base
12
- // SPDX-License-Identifier: Apache-2.0
13
-
14
- const NETWORK_USE_UNLIMITED_WEIGHT = ['acala', 'karura', 'statemint'];
15
-
16
- // function getTokenIdentity (originNetworkKey: string, tokenInfo: TokenInfo) {
17
- // // TODO: find a better way to handle kUSD on karura
18
- // const tokenSymbol = tokenInfo.symbol.toUpperCase() === 'AUSD' && originNetworkKey === 'karura' ? 'KUSD' : tokenInfo.symbol.toUpperCase();
19
- //
20
- // if (originNetworkKey === 'bifrost') {
21
- // return tokenInfo.specialOption as Record<string, any>;
22
- // } else if (originNetworkKey === 'pioneer' && tokenSymbol.toUpperCase() === 'NEER') {
23
- // return {
24
- // NativeToken: 0
25
- // };
26
- // } else if (originNetworkKey === 'karura' && tokenSymbol.toUpperCase() === 'NEER') { // TODO: modify later with different assets on Karura
27
- // return tokenInfo.specialOption as Record<string, any>;
28
- // } else if (originNetworkKey === 'acala' && tokenSymbol.toUpperCase() === 'GLMR') { // TODO: modify later with different assets on Acala
29
- // return tokenInfo.specialOption as Record<string, any>;
30
- // }
31
- //
32
- // return {
33
- // Token: tokenSymbol
34
- // };
35
- // }
36
-
37
- async function substrateEstimateCrossChainFee(originNetworkKey, destinationNetworkKey, recipient, sender, sendingValue, substrateApiMap, originTokenInfo, chainInfoMap) {
38
- const substrateApi = await substrateApiMap[originNetworkKey].isReady;
39
- const api = substrateApi.api;
40
- let fee = '0';
41
- const originChainInfo = chainInfoMap[originNetworkKey];
42
- const destinationChainInfo = chainInfoMap[destinationNetworkKey];
43
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
44
- const tokenIdentity = (0, _utils2._getXcmAssetMultilocation)(originTokenInfo);
45
- const weightParam = _constants._XCM_CHAIN_USE_LIMITED_WEIGHT.includes(originNetworkKey) ? _utils.POLKADOT_UNLIMITED_WEIGHT : _utils.FOUR_INSTRUCTIONS_WEIGHT;
46
- try {
47
- if ((0, _utils2._isSubstrateParaChain)(originChainInfo)) {
48
- // Case ParaChain -> ParaChain && ParaChain -> RelayChain
49
- const extrinsic = api.tx.xTokens.transfer(tokenIdentity, sendingValue, (0, _utils.getMultiLocationFromParachain)(originNetworkKey, destinationNetworkKey, chainInfoMap, recipient), weightParam);
50
- try {
51
- const paymentInfo = await extrinsic.paymentInfo(sender.address);
52
- fee = paymentInfo.partialFee.toString();
53
- } catch (e) {
54
- console.error(e);
55
- }
56
- console.log('substrate xcm tx p-p or p-r here', extrinsic.toHex());
57
- } else {
58
- // Case RelayChain -> ParaChain
59
- const receiverLocation = (0, _utils.getReceiverLocation)(originNetworkKey, destinationNetworkKey, chainInfoMap, recipient);
60
- if (_constants._XCM_CHAIN_GROUP.statemine.includes(destinationNetworkKey)) {
61
- const extrinsic = api.tx.xcmPallet.limitedTeleportAssets({
62
- V1: {
63
- parents: 0,
64
- interior: {
65
- X1: {
66
- Parachain: (0, _utils2._getSubstrateParaId)(destinationChainInfo)
67
- }
68
- }
69
- }
70
- }, {
71
- V1: {
72
- parents: 0,
73
- interior: {
74
- X1: receiverLocation
75
- }
76
- }
77
- }, {
78
- V1: [{
79
- id: {
80
- Concrete: {
81
- parents: 0,
82
- interior: 'Here'
83
- }
84
- },
85
- fun: {
86
- Fungible: sendingValue
87
- }
88
- }]
89
- }, 0, _utils.POLKADOT_UNLIMITED_WEIGHT);
90
- const paymentInfo = await extrinsic.paymentInfo(sender);
91
- fee = paymentInfo.partialFee.toString();
92
- console.log('substrate xcm teleport asset tx r-p here', extrinsic.toHex());
93
- } else {
94
- const extrinsic = api.tx.xcmPallet.reserveTransferAssets({
95
- V1: {
96
- // find the destination chain
97
- parents: 0,
98
- interior: {
99
- X1: {
100
- Parachain: (0, _utils2._getSubstrateParaId)(destinationChainInfo)
101
- }
102
- }
103
- }
104
- }, {
105
- V1: {
106
- // find the receiver
107
- parents: 0,
108
- interior: {
109
- X1: receiverLocation
110
- }
111
- }
112
- }, {
113
- V1: [
114
- // find the asset
115
- {
116
- id: {
117
- Concrete: {
118
- parents: 0,
119
- interior: 'Here'
120
- }
121
- },
122
- fun: {
123
- Fungible: sendingValue
124
- }
125
- }]
126
- }, 0);
127
- const paymentInfo = await extrinsic.paymentInfo(sender);
128
- fee = paymentInfo.partialFee.toString();
129
- console.log('substrate xcm reserve transfer tx r-p here', extrinsic.toHex());
130
- }
131
- }
132
- } catch (e) {
133
- console.error('error parsing xcm transaction', e);
134
- }
135
- return fee;
136
- }
137
- function substrateGetXcmExtrinsic(originNetworkKey, destinationNetworkKey, recipient, sendingValue, api, originTokenInfo, chainInfoMap) {
138
- // Case ParaChain -> RelayChain && Parachain -> Parachain
139
- if ((0, _utils2._isSubstrateParaChain)(chainInfoMap[originNetworkKey])) {
140
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
141
- const tokenIdentity = (0, _utils2._getXcmAssetMultilocation)(originTokenInfo);
142
- const weightParam = NETWORK_USE_UNLIMITED_WEIGHT.includes(originNetworkKey) ? _utils.POLKADOT_UNLIMITED_WEIGHT : _utils.FOUR_INSTRUCTIONS_WEIGHT;
143
- return api.tx.xTokens.transfer(tokenIdentity, sendingValue, (0, _utils.getMultiLocationFromParachain)(originNetworkKey, destinationNetworkKey, chainInfoMap, recipient), weightParam);
144
- }
145
-
146
- // Case RelayChain -> Parachain
147
- const destinationChainInfo = chainInfoMap[destinationNetworkKey];
148
- const receiverLocation = (0, _utils.getReceiverLocation)(originNetworkKey, destinationNetworkKey, chainInfoMap, recipient);
149
- if (_constants._XCM_CHAIN_GROUP.statemine.includes(destinationNetworkKey)) {
150
- return api.tx.xcmPallet.limitedTeleportAssets({
151
- V1: {
152
- parents: 0,
153
- interior: {
154
- X1: {
155
- Parachain: (0, _utils2._getSubstrateParaId)(destinationChainInfo)
156
- }
157
- }
158
- }
159
- }, {
160
- V1: {
161
- parents: 0,
162
- interior: {
163
- X1: receiverLocation
164
- }
165
- }
166
- }, {
167
- V1: [{
168
- id: {
169
- Concrete: {
170
- parents: 0,
171
- interior: 'Here'
172
- }
173
- },
174
- fun: {
175
- Fungible: sendingValue
176
- }
177
- }]
178
- }, 0, _utils.POLKADOT_UNLIMITED_WEIGHT);
179
- }
180
- return api.tx.xcmPallet.reserveTransferAssets({
181
- V1: {
182
- // find the destination chain
183
- parents: 0,
184
- interior: {
185
- X1: {
186
- Parachain: (0, _utils2._getSubstrateParaId)(destinationChainInfo)
187
- }
188
- }
189
- }
190
- }, {
191
- V1: {
192
- // find the receiver
193
- parents: 0,
194
- interior: {
195
- X1: receiverLocation
196
- }
197
- }
198
- }, {
199
- V1: [
200
- // find the asset
201
- {
202
- id: {
203
- Concrete: {
204
- parents: 0,
205
- interior: 'Here'
206
- }
207
- },
208
- fun: {
209
- Fungible: sendingValue
210
- }
211
- }]
212
- }, 0);
213
- }
@@ -1,20 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- var _util = require("@polkadot/util");
8
- // Copyright 2019-2022 @subwallet/extension-koni authors & contributors
9
- // SPDX-License-Identifier: Apache-2.0
10
-
11
- class BaseMigrationJob {
12
- constructor(state) {
13
- this.state = state;
14
- this.logger = (0, _util.logger)(this.constructor.name);
15
- }
16
- run() {
17
- return Promise.resolve(console.warn('Need to override function run from base.'));
18
- }
19
- }
20
- exports.default = BaseMigrationJob;
@@ -1,45 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.default = void 0;
8
- var _util = require("@polkadot/util");
9
- var _scripts = _interopRequireDefault(require("./scripts"));
10
- // Copyright 2019-2022 @subwallet/extension-koni authors & contributors
11
- // SPDX-License-Identifier: Apache-2.0
12
-
13
- class Migration {
14
- constructor(state) {
15
- this.state = state;
16
- this.logger = (0, _util.logger)('Migration');
17
- }
18
- async run() {
19
- this.logger.log('Migrating...');
20
- const keys = Object.keys(_scripts.default).sort((a, b) => a.localeCompare(b));
21
- try {
22
- for (let i = 0; i < keys.length; i++) {
23
- const JobClass = _scripts.default[keys[i]];
24
- const check = await this.state.dbService.stores.migration.table.where({
25
- name: JobClass.name,
26
- key: keys[i]
27
- }).first();
28
- if (!check) {
29
- const job = new JobClass(this.state);
30
- this.logger.log('Running script: ', JobClass.name);
31
- await job.run();
32
- await this.state.dbService.stores.migration.table.put({
33
- key: keys[i],
34
- name: JobClass.name,
35
- timestamp: +new Date()
36
- });
37
- }
38
- }
39
- } catch (error) {
40
- this.logger.warn('Migration error: ', error);
41
- }
42
- this.logger.log('Migration done.');
43
- }
44
- }
45
- exports.default = Migration;
@@ -1,22 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.default = void 0;
8
- var _Base = _interopRequireDefault(require("@subwallet/extension-base/koni/migration/Base"));
9
- // Copyright 2019-2022 @subwallet/extension-koni authors & contributors
10
- // SPDX-License-Identifier: Apache-2.0
11
-
12
- class ChangeRouteToHome extends _Base.default {
13
- async run() {
14
- const deletedRoutes = ['/account/import-evm-token', '/account/import-evm-nft', '/account/evm-token-setting', '/account/evm-token-edit', '/account/import-evm-token', '/account/import-evm-nft', '/account/evm-token-setting', '/account/evm-token-edit'];
15
- const currentRoute = window.localStorage.getItem('popupNavigation');
16
- if (currentRoute !== null && deletedRoutes.includes(currentRoute)) {
17
- window.localStorage.setItem('popupNavigation', '/');
18
- }
19
- return Promise.resolve();
20
- }
21
- }
22
- exports.default = ChangeRouteToHome;
@@ -1,24 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.default = void 0;
8
- var _Base = _interopRequireDefault(require("@subwallet/extension-base/koni/migration/Base"));
9
- // Copyright 2019-2022 @subwallet/extension-koni authors & contributors
10
- // SPDX-License-Identifier: Apache-2.0
11
-
12
- class ClearOldStorage extends _Base.default {
13
- async run() {
14
- // new BalanceStore().removeAll();
15
- // new CrowdloanStore().removeAll();
16
- // new StakingStore().removeAll();
17
- // new NftStore().removeAll();
18
- // new NftCollectionStore().removeAll();
19
- // // Todo: clear transaction history data
20
-
21
- return Promise.resolve();
22
- }
23
- }
24
- exports.default = ClearOldStorage;
@@ -1,36 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.default = void 0;
8
- var _Base = _interopRequireDefault(require("@subwallet/extension-base/koni/migration/Base"));
9
- var _TransactionHistoryV = _interopRequireDefault(require("@subwallet/extension-base/stores/TransactionHistoryV3"));
10
- var _accounts = require("@subwallet/ui-keyring/observable/accounts");
11
- // Copyright 2019-2022 @subwallet/extension-koni authors & contributors
12
- // SPDX-License-Identifier: Apache-2.0
13
-
14
- class RemoveWrongTransactionHistoriesFromStore extends _Base.default {
15
- async run() {
16
- const newStore = new _TransactionHistoryV.default();
17
- const addressList = Object.keys(_accounts.accounts.subject.value);
18
- for (const address of addressList) {
19
- const oldHistories = await newStore.asyncGet(address);
20
- const newHistories = {};
21
- Object.entries(oldHistories).forEach(_ref => {
22
- let [hash, items] = _ref;
23
- // Remove wrong stored history (missing eventIdx)
24
- const newItems = items.items.filter(item => item.origin === 'app');
25
- newHistories[hash] = {
26
- items: newItems,
27
- total: newItems.length
28
- };
29
- });
30
- if (Object.keys(newHistories).length > 0) {
31
- newStore.set(address, newHistories);
32
- }
33
- }
34
- }
35
- }
36
- exports.default = RemoveWrongTransactionHistoriesFromStore;
@@ -1,21 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.default = void 0;
8
- var _Base = _interopRequireDefault(require("@subwallet/extension-base/koni/migration/Base"));
9
- var _databases = _interopRequireDefault(require("@subwallet/extension-base/services/storage-service/databases"));
10
- // Copyright 2019-2022 @subwallet/extension-koni authors & contributors
11
- // SPDX-License-Identifier: Apache-2.0
12
-
13
- class ResetTransactionHistoryEventIdx extends _Base.default {
14
- async run() {
15
- const db = new _databases.default();
16
- const oldData = await db.transactions.toArray();
17
- await db.transactions.clear();
18
- await db.transactions.bulkAdd(oldData);
19
- }
20
- }
21
- exports.default = ResetTransactionHistoryEventIdx;
@@ -1,22 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.default = void 0;
8
- var _ChangeRouteToHome = _interopRequireDefault(require("@subwallet/extension-base/koni/migration/scripts/ChangeRouteToHome"));
9
- var _RemoveWrongCrowdloan = _interopRequireDefault(require("@subwallet/extension-base/koni/migration/scripts/RemoveWrongCrowdloan"));
10
- var _ResetTransactionHistoryEventIdx = _interopRequireDefault(require("@subwallet/extension-base/koni/migration/scripts/ResetTransactionHistoryEventIdx"));
11
- var _ClearOldStorage = _interopRequireDefault(require("./ClearOldStorage"));
12
- // Copyright 2019-2022 @subwallet/extension-koni authors & contributors
13
- // SPDX-License-Identifier: Apache-2.0
14
- var _default = {
15
- // '0.5.3-2': FixMissingTransactionHistory,
16
- // '0.5.3-3-1': ConvertTransactionHistoryFromChromeStorageToIndexedDB, // Can run multiple times with different key
17
- '0.5.6-1': _ClearOldStorage.default,
18
- '0.6.6-1': _ChangeRouteToHome.default,
19
- '0.7.5-0': _ResetTransactionHistoryEventIdx.default,
20
- '0.7.9-0': _RemoveWrongCrowdloan.default
21
- };
22
- exports.default = _default;
@@ -1,16 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.initEvmProvider = initEvmProvider;
7
- var _SubWalleEvmProvider = require("@subwallet/extension-base/koni/page/SubWalleEvmProvider");
8
- var _page = require("@subwallet/extension-base/page");
9
- // Copyright 2019-2022 @subwallet/extension-koni authors & contributors
10
- // SPDX-License-Identifier: Apache-2.0
11
-
12
- // the enable function, called by the dapp to allow access
13
-
14
- function initEvmProvider(version) {
15
- return new _SubWalleEvmProvider.SubWalletEvmProvider(_page.sendMessage, version);
16
- }