@subwallet/extension-base 1.1.33-0 → 1.1.33-beta.1

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 (314) hide show
  1. package/background/KoniTypes.d.ts +120 -69
  2. package/background/KoniTypes.js +22 -13
  3. package/background/errors/TransactionError.js +9 -0
  4. package/cjs/background/KoniTypes.js +23 -16
  5. package/cjs/background/errors/TransactionError.js +9 -0
  6. package/cjs/constants/index.js +19 -4
  7. package/cjs/koni/api/dotsama/balance.js +464 -0
  8. package/cjs/koni/api/nft/config.js +33 -23
  9. package/cjs/koni/api/nft/index.js +14 -0
  10. package/cjs/koni/api/nft/nft.js +1 -22
  11. package/cjs/koni/api/nft/ordinal_nft/constants.js +21 -0
  12. package/cjs/koni/api/nft/ordinal_nft/index.js +121 -0
  13. package/cjs/koni/api/nft/ordinal_nft/utils.js +41 -0
  14. package/cjs/koni/api/staking/bonding/amplitude.js +31 -28
  15. package/cjs/koni/api/staking/bonding/astar.js +11 -10
  16. package/cjs/koni/api/staking/bonding/index.js +4 -1
  17. package/cjs/koni/api/staking/bonding/paraChain.js +25 -23
  18. package/cjs/koni/api/staking/bonding/relayChain.js +48 -45
  19. package/cjs/koni/api/staking/bonding/utils.js +104 -86
  20. package/cjs/koni/api/staking/index.js +6 -5
  21. package/cjs/koni/api/staking/paraChain.js +6 -5
  22. package/cjs/koni/api/staking/relayChain.js +3 -2
  23. package/cjs/koni/api/yield/helper/utils.js +49 -0
  24. package/cjs/koni/background/cron.js +3 -21
  25. package/cjs/koni/background/handlers/Extension.js +368 -69
  26. package/cjs/koni/background/handlers/State.js +18 -12
  27. package/cjs/koni/background/handlers/index.js +4 -2
  28. package/cjs/koni/background/subscription.js +7 -104
  29. package/cjs/services/campaign-service/index.js +9 -6
  30. package/cjs/services/chain-service/constants.js +4 -17
  31. package/cjs/services/chain-service/handler/SubstrateApi.js +10 -5
  32. package/cjs/services/chain-service/index.js +123 -39
  33. package/cjs/services/chain-service/utils.js +75 -1
  34. package/cjs/services/earning-service/constants/chains.js +30 -0
  35. package/cjs/services/earning-service/constants/index.js +27 -0
  36. package/cjs/services/earning-service/constants/step.js +18 -0
  37. package/cjs/services/earning-service/handlers/base.js +262 -0
  38. package/cjs/services/earning-service/handlers/index.js +60 -0
  39. package/cjs/services/earning-service/handlers/lending/base.js +81 -0
  40. package/cjs/services/earning-service/handlers/lending/index.js +13 -0
  41. package/cjs/services/earning-service/handlers/lending/interlay.js +192 -0
  42. package/cjs/services/earning-service/handlers/liquid-staking/acala.js +240 -0
  43. package/cjs/services/earning-service/handlers/liquid-staking/base.js +98 -0
  44. package/cjs/services/earning-service/handlers/liquid-staking/bifrost-manta.js +140 -0
  45. package/cjs/services/earning-service/handlers/liquid-staking/bifrost.js +299 -0
  46. package/cjs/services/earning-service/handlers/liquid-staking/index.js +41 -0
  47. package/cjs/services/earning-service/handlers/liquid-staking/parallel.js +227 -0
  48. package/cjs/services/earning-service/handlers/liquid-staking/stella-swap.js +404 -0
  49. package/cjs/services/earning-service/handlers/native-staking/amplitude.js +434 -0
  50. package/cjs/services/earning-service/handlers/native-staking/astar.js +466 -0
  51. package/cjs/services/earning-service/handlers/native-staking/base-para.js +146 -0
  52. package/cjs/services/earning-service/handlers/native-staking/base.js +161 -0
  53. package/cjs/services/earning-service/handlers/native-staking/index.js +34 -0
  54. package/cjs/services/earning-service/handlers/native-staking/para-chain.js +390 -0
  55. package/cjs/services/earning-service/handlers/native-staking/relay-chain.js +567 -0
  56. package/cjs/services/earning-service/handlers/nomination-pool/index.js +566 -0
  57. package/cjs/services/earning-service/handlers/special.js +497 -0
  58. package/cjs/services/earning-service/service.js +741 -0
  59. package/cjs/services/earning-service/utils/index.js +128 -0
  60. package/cjs/services/event-service/index.js +5 -0
  61. package/cjs/services/keyring-service/index.js +14 -2
  62. package/cjs/services/migration-service/scripts/DeleteEarningData.js +21 -0
  63. package/cjs/services/migration-service/scripts/EnableEarningChains.js +21 -0
  64. package/cjs/services/migration-service/scripts/MigrateEthProvider.js +17 -0
  65. package/cjs/services/migration-service/scripts/MigrateLedgerAccount.js +1 -1
  66. package/cjs/services/migration-service/scripts/MigratePioneerProvider.js +17 -0
  67. package/cjs/services/migration-service/scripts/MigrateProvider.js +29 -0
  68. package/cjs/services/migration-service/scripts/MigrateTransactionHistory.js +1 -1
  69. package/cjs/services/migration-service/scripts/databases/MigrateEarningHistory.js +21 -0
  70. package/cjs/services/migration-service/scripts/databases/MigrateEarningVersion.js +21 -0
  71. package/cjs/services/migration-service/scripts/index.js +6 -1
  72. package/cjs/services/mint-campaign-service/campaigns/UnlockDotCampaign.js +149 -0
  73. package/cjs/services/mint-campaign-service/campaigns/index.js +13 -0
  74. package/cjs/services/mint-campaign-service/constants.js +11 -0
  75. package/cjs/services/mint-campaign-service/index.js +18 -0
  76. package/cjs/services/notification-service/NotificationService.js +1 -1
  77. package/cjs/services/storage-service/DatabaseService.js +92 -1
  78. package/cjs/services/storage-service/databases/index.js +7 -0
  79. package/cjs/services/storage-service/db-stores/AssetRef.js +24 -0
  80. package/cjs/services/storage-service/db-stores/NominatorMetadata.js +3 -3
  81. package/cjs/services/storage-service/db-stores/YieldPoolStore.js +36 -0
  82. package/cjs/services/storage-service/db-stores/YieldPositionStore.js +71 -0
  83. package/cjs/services/storage-service/index.js +241 -0
  84. package/cjs/services/subscan-service/index.js +16 -0
  85. package/cjs/services/transaction-service/event-parser/index.js +58 -0
  86. package/cjs/services/transaction-service/helpers/index.js +3 -1
  87. package/cjs/services/transaction-service/index.js +252 -75
  88. package/cjs/services/transaction-service/utils.js +1 -0
  89. package/cjs/types/campaigns/index.js +16 -0
  90. package/cjs/types/campaigns/unlock-dot.js +1 -0
  91. package/cjs/types/index.js +44 -0
  92. package/cjs/types/ordinal.js +1 -0
  93. package/cjs/types/transaction.js +1 -0
  94. package/cjs/types/yield/actions/index.js +27 -0
  95. package/cjs/types/yield/actions/join/index.js +38 -0
  96. package/cjs/types/yield/actions/join/step.js +48 -0
  97. package/cjs/types/yield/actions/join/submit.js +1 -0
  98. package/cjs/types/yield/actions/join/validate.js +16 -0
  99. package/cjs/types/yield/actions/others.js +1 -0
  100. package/cjs/types/yield/index.js +27 -0
  101. package/cjs/types/yield/info/account/index.js +49 -0
  102. package/cjs/types/yield/info/account/info.js +1 -0
  103. package/cjs/types/yield/info/account/reward.js +1 -0
  104. package/cjs/types/yield/info/account/target.js +32 -0
  105. package/cjs/types/yield/info/account/unstake.js +27 -0
  106. package/cjs/types/yield/info/base.js +41 -0
  107. package/cjs/types/yield/info/chain/index.js +27 -0
  108. package/cjs/types/yield/info/chain/info.js +1 -0
  109. package/cjs/types/yield/info/chain/target.js +1 -0
  110. package/cjs/types/yield/info/index.js +49 -0
  111. package/cjs/types/yield/info/pallet.js +15 -0
  112. package/cjs/types.js +1 -0
  113. package/cjs/utils/address.js +34 -0
  114. package/cjs/utils/fetchStaticData.js +2 -1
  115. package/cjs/utils/index.js +89 -1
  116. package/cjs/utils/keyring.js +57 -0
  117. package/cjs/utils/number.js +6 -2
  118. package/cjs/utils/object.js +12 -0
  119. package/constants/index.d.ts +6 -1
  120. package/constants/index.js +6 -1
  121. package/koni/api/nft/config.js +33 -23
  122. package/koni/api/nft/index.js +15 -1
  123. package/koni/api/nft/nft.js +2 -23
  124. package/koni/api/nft/ordinal_nft/constants.d.ts +9 -0
  125. package/koni/api/nft/ordinal_nft/constants.js +12 -0
  126. package/koni/api/nft/ordinal_nft/index.d.ts +8 -0
  127. package/koni/api/nft/ordinal_nft/index.js +114 -0
  128. package/koni/api/nft/ordinal_nft/utils.d.ts +2 -0
  129. package/koni/api/nft/ordinal_nft/utils.js +33 -0
  130. package/koni/api/staking/bonding/amplitude.js +25 -22
  131. package/koni/api/staking/bonding/astar.js +9 -8
  132. package/koni/api/staking/bonding/index.d.ts +1 -1
  133. package/koni/api/staking/bonding/index.js +5 -1
  134. package/koni/api/staking/bonding/paraChain.js +12 -10
  135. package/koni/api/staking/bonding/relayChain.d.ts +2 -2
  136. package/koni/api/staking/bonding/relayChain.js +33 -30
  137. package/koni/api/staking/bonding/utils.d.ts +15 -38
  138. package/koni/api/staking/bonding/utils.js +85 -69
  139. package/koni/api/staking/index.js +2 -1
  140. package/koni/api/staking/paraChain.js +7 -6
  141. package/koni/api/staking/relayChain.js +4 -3
  142. package/koni/api/yield/helper/utils.d.ts +10 -0
  143. package/koni/api/yield/helper/utils.js +34 -0
  144. package/koni/background/cron.d.ts +0 -4
  145. package/koni/background/cron.js +4 -22
  146. package/koni/background/handlers/Extension.d.ts +17 -1
  147. package/koni/background/handlers/Extension.js +327 -30
  148. package/koni/background/handlers/State.d.ts +6 -1
  149. package/koni/background/handlers/State.js +17 -12
  150. package/koni/background/handlers/index.js +4 -2
  151. package/koni/background/subscription.d.ts +1 -6
  152. package/koni/background/subscription.js +8 -104
  153. package/package.json +327 -4
  154. package/services/campaign-service/index.js +9 -6
  155. package/services/chain-service/constants.d.ts +1 -12
  156. package/services/chain-service/constants.js +1 -14
  157. package/services/chain-service/handler/SubstrateApi.js +10 -5
  158. package/services/chain-service/index.d.ts +11 -1
  159. package/services/chain-service/index.js +119 -36
  160. package/services/chain-service/utils.d.ts +11 -1
  161. package/services/chain-service/utils.js +71 -2
  162. package/services/earning-service/constants/abis/compound_finance_v2_abi.json +1235 -0
  163. package/services/earning-service/constants/abis/st_liquid_token_abi.json +1355 -0
  164. package/services/earning-service/constants/chains.d.ts +15 -0
  165. package/services/earning-service/constants/chains.js +22 -0
  166. package/services/earning-service/constants/index.d.ts +2 -0
  167. package/services/earning-service/constants/index.js +5 -0
  168. package/services/earning-service/constants/step.d.ts +3 -0
  169. package/services/earning-service/constants/step.js +10 -0
  170. package/services/earning-service/handlers/base.d.ts +113 -0
  171. package/services/earning-service/handlers/base.js +256 -0
  172. package/services/earning-service/handlers/index.d.ts +5 -0
  173. package/services/earning-service/handlers/index.js +8 -0
  174. package/services/earning-service/handlers/lending/base.d.ts +8 -0
  175. package/services/earning-service/handlers/lending/base.js +73 -0
  176. package/services/earning-service/handlers/lending/index.d.ts +1 -0
  177. package/services/earning-service/handlers/lending/index.js +4 -0
  178. package/services/earning-service/handlers/lending/interlay.d.ts +24 -0
  179. package/services/earning-service/handlers/lending/interlay.js +184 -0
  180. package/services/earning-service/handlers/liquid-staking/acala.d.ts +27 -0
  181. package/services/earning-service/handlers/liquid-staking/acala.js +232 -0
  182. package/services/earning-service/handlers/liquid-staking/base.d.ts +11 -0
  183. package/services/earning-service/handlers/liquid-staking/base.js +90 -0
  184. package/services/earning-service/handlers/liquid-staking/bifrost-manta.d.ts +37 -0
  185. package/services/earning-service/handlers/liquid-staking/bifrost-manta.js +132 -0
  186. package/services/earning-service/handlers/liquid-staking/bifrost.d.ts +46 -0
  187. package/services/earning-service/handlers/liquid-staking/bifrost.js +288 -0
  188. package/services/earning-service/handlers/liquid-staking/index.d.ts +5 -0
  189. package/services/earning-service/handlers/liquid-staking/index.js +8 -0
  190. package/services/earning-service/handlers/liquid-staking/parallel.d.ts +26 -0
  191. package/services/earning-service/handlers/liquid-staking/parallel.js +219 -0
  192. package/services/earning-service/handlers/liquid-staking/stella-swap.d.ts +34 -0
  193. package/services/earning-service/handlers/liquid-staking/stella-swap.js +394 -0
  194. package/services/earning-service/handlers/native-staking/amplitude.d.ts +22 -0
  195. package/services/earning-service/handlers/native-staking/amplitude.js +425 -0
  196. package/services/earning-service/handlers/native-staking/astar.d.ts +19 -0
  197. package/services/earning-service/handlers/native-staking/astar.js +456 -0
  198. package/services/earning-service/handlers/native-staking/base-para.d.ts +11 -0
  199. package/services/earning-service/handlers/native-staking/base-para.js +138 -0
  200. package/services/earning-service/handlers/native-staking/base.d.ts +21 -0
  201. package/services/earning-service/handlers/native-staking/base.js +152 -0
  202. package/services/earning-service/handlers/native-staking/index.d.ts +4 -0
  203. package/services/earning-service/handlers/native-staking/index.js +7 -0
  204. package/services/earning-service/handlers/native-staking/para-chain.d.ts +15 -0
  205. package/services/earning-service/handlers/native-staking/para-chain.js +382 -0
  206. package/services/earning-service/handlers/native-staking/relay-chain.d.ts +21 -0
  207. package/services/earning-service/handlers/native-staking/relay-chain.js +558 -0
  208. package/services/earning-service/handlers/nomination-pool/index.d.ts +36 -0
  209. package/services/earning-service/handlers/nomination-pool/index.js +556 -0
  210. package/services/earning-service/handlers/special.d.ts +64 -0
  211. package/services/earning-service/handlers/special.js +489 -0
  212. package/services/earning-service/service.d.ts +94 -0
  213. package/services/earning-service/service.js +730 -0
  214. package/services/earning-service/utils/index.d.ts +18 -0
  215. package/services/earning-service/utils/index.js +112 -0
  216. package/services/event-service/index.d.ts +2 -0
  217. package/services/event-service/index.js +5 -0
  218. package/services/event-service/types.d.ts +9 -0
  219. package/services/keyring-service/index.d.ts +2 -1
  220. package/services/keyring-service/index.js +14 -2
  221. package/services/migration-service/scripts/DeleteEarningData.d.ts +4 -0
  222. package/services/migration-service/scripts/DeleteEarningData.js +13 -0
  223. package/services/migration-service/scripts/EnableEarningChains.d.ts +4 -0
  224. package/services/migration-service/scripts/EnableEarningChains.js +13 -0
  225. package/services/migration-service/scripts/MigrateLedgerAccount.js +1 -1
  226. package/services/migration-service/scripts/MigrateTransactionHistory.js +1 -1
  227. package/services/migration-service/scripts/databases/MigrateEarningHistory.d.ts +4 -0
  228. package/services/migration-service/scripts/databases/MigrateEarningHistory.js +13 -0
  229. package/services/migration-service/scripts/databases/MigrateEarningVersion.d.ts +4 -0
  230. package/services/migration-service/scripts/databases/MigrateEarningVersion.js +13 -0
  231. package/services/migration-service/scripts/index.js +6 -1
  232. package/services/mint-campaign-service/campaigns/UnlockDotCampaign.d.ts +13 -0
  233. package/services/mint-campaign-service/campaigns/UnlockDotCampaign.js +139 -0
  234. package/services/mint-campaign-service/campaigns/index.d.ts +1 -0
  235. package/services/mint-campaign-service/campaigns/index.js +4 -0
  236. package/services/mint-campaign-service/constants.d.ts +1 -0
  237. package/services/mint-campaign-service/constants.js +4 -0
  238. package/services/mint-campaign-service/index.d.ts +7 -0
  239. package/services/mint-campaign-service/index.js +11 -0
  240. package/services/notification-service/NotificationService.js +1 -1
  241. package/services/storage-service/DatabaseService.d.ts +30 -3
  242. package/services/storage-service/DatabaseService.js +91 -1
  243. package/services/storage-service/databases/index.d.ts +8 -2
  244. package/services/storage-service/databases/index.js +7 -0
  245. package/services/storage-service/db-stores/AssetRef.d.ts +7 -0
  246. package/services/storage-service/db-stores/AssetRef.js +16 -0
  247. package/services/storage-service/db-stores/NominatorMetadata.js +3 -3
  248. package/services/storage-service/db-stores/YieldPoolStore.d.ts +10 -0
  249. package/services/storage-service/db-stores/YieldPoolStore.js +28 -0
  250. package/services/storage-service/db-stores/YieldPositionStore.d.ts +11 -0
  251. package/services/storage-service/db-stores/YieldPositionStore.js +63 -0
  252. package/services/subscan-service/index.d.ts +3 -2
  253. package/services/subscan-service/index.js +15 -0
  254. package/services/subscan-service/types.d.ts +20 -0
  255. package/services/transaction-service/event-parser/index.d.ts +3 -1
  256. package/services/transaction-service/event-parser/index.js +57 -1
  257. package/services/transaction-service/helpers/index.js +3 -1
  258. package/services/transaction-service/index.d.ts +6 -13
  259. package/services/transaction-service/index.js +250 -73
  260. package/services/transaction-service/types.d.ts +2 -0
  261. package/services/transaction-service/utils.js +1 -0
  262. package/types/campaigns/index.d.ts +1 -0
  263. package/types/campaigns/index.js +4 -0
  264. package/types/campaigns/unlock-dot.d.ts +71 -0
  265. package/types/campaigns/unlock-dot.js +1 -0
  266. package/types/index.d.ts +5 -0
  267. package/types/index.js +5 -1
  268. package/types/ordinal.d.ts +69 -0
  269. package/types/ordinal.js +1 -0
  270. package/types/transaction.d.ts +3 -0
  271. package/types/transaction.js +1 -0
  272. package/types/yield/actions/index.d.ts +2 -0
  273. package/types/yield/actions/index.js +5 -0
  274. package/types/yield/actions/join/index.d.ts +3 -0
  275. package/types/yield/actions/join/index.js +6 -0
  276. package/types/yield/actions/join/step.d.ts +96 -0
  277. package/types/yield/actions/join/step.js +47 -0
  278. package/types/yield/actions/join/submit.d.ts +58 -0
  279. package/types/yield/actions/join/submit.js +1 -0
  280. package/types/yield/actions/join/validate.d.ts +18 -0
  281. package/types/yield/actions/join/validate.js +10 -0
  282. package/types/yield/actions/others.d.ts +85 -0
  283. package/types/yield/actions/others.js +1 -0
  284. package/types/yield/index.d.ts +2 -0
  285. package/types/yield/index.js +5 -0
  286. package/types/yield/info/account/index.d.ts +4 -0
  287. package/types/yield/info/account/index.js +7 -0
  288. package/types/yield/info/account/info.d.ts +92 -0
  289. package/types/yield/info/account/info.js +1 -0
  290. package/types/yield/info/account/reward.d.ts +47 -0
  291. package/types/yield/info/account/reward.js +1 -0
  292. package/types/yield/info/account/target.d.ts +43 -0
  293. package/types/yield/info/account/target.js +27 -0
  294. package/types/yield/info/account/unstake.d.ts +31 -0
  295. package/types/yield/info/account/unstake.js +22 -0
  296. package/types/yield/info/base.d.ts +45 -0
  297. package/types/yield/info/base.js +36 -0
  298. package/types/yield/info/chain/index.d.ts +2 -0
  299. package/types/yield/info/chain/index.js +5 -0
  300. package/types/yield/info/chain/info.d.ts +252 -0
  301. package/types/yield/info/chain/info.js +1 -0
  302. package/types/yield/info/chain/target.d.ts +37 -0
  303. package/types/yield/info/chain/target.js +1 -0
  304. package/types/yield/info/index.d.ts +4 -0
  305. package/types/yield/info/index.js +7 -0
  306. package/types/yield/info/pallet.d.ts +143 -0
  307. package/types/yield/info/pallet.js +9 -0
  308. package/utils/fetchStaticData.js +2 -1
  309. package/utils/index.d.ts +5 -0
  310. package/utils/index.js +52 -0
  311. package/utils/number.d.ts +2 -1
  312. package/utils/number.js +2 -1
  313. package/utils/object.d.ts +1 -0
  314. package/utils/object.js +6 -0
@@ -33,18 +33,6 @@ export declare const _NFT_CHAIN_GROUP: {
33
33
  bitcountry: string[];
34
34
  vara: string[];
35
35
  };
36
- export declare const _STAKING_CHAIN_GROUP: {
37
- relay: string[];
38
- para: string[];
39
- astar: string[];
40
- amplitude: string[];
41
- krest_network: string[];
42
- kilt: string[];
43
- nominationPool: string[];
44
- bifrost: string[];
45
- aleph: string[];
46
- ternoa: string[];
47
- };
48
36
  export declare const _STAKING_ERA_LENGTH_MAP: Record<string, number>;
49
37
  export declare const _EXPECTED_BLOCK_TIME: Record<string, number>;
50
38
  export declare const _PARACHAIN_INFLATION_DISTRIBUTION: Record<string, Record<string, number>>;
@@ -96,6 +84,7 @@ export declare const EVM_PASS_CONNECT_STATUS: Record<string, string[]>;
96
84
  export declare const EVM_REFORMAT_DECIMALS: {
97
85
  acala: string[];
98
86
  };
87
+ export declare const LATEST_CHAIN_DATA_FETCHING_INTERVAL = 30000;
99
88
  export declare const _CHAIN_INFO_SRC: string;
100
89
  export declare const _CHAIN_ASSET_SRC: string;
101
90
  export declare const _ASSET_REF_SRC: string;
@@ -52,20 +52,6 @@ export const _NFT_CHAIN_GROUP = {
52
52
 
53
53
  // Staking--------------------------------------------------------------------------------------------------------------
54
54
 
55
- export const _STAKING_CHAIN_GROUP = {
56
- relay: ['polkadot', 'kusama', 'aleph', 'polkadex', 'ternoa', 'ternoa_alphanet', 'alephTest', 'polkadexTest', 'westend', 'kate', 'edgeware', 'creditcoin', 'vara_network', 'goldberg_testnet'],
57
- para: ['moonbeam', 'moonriver', 'moonbase', 'turing', 'turingStaging', 'bifrost', 'bifrost_testnet', 'calamari_test', 'calamari', 'manta_network'],
58
- astar: ['astar', 'shiden', 'shibuya'],
59
- amplitude: ['amplitude', 'amplitude_test', 'kilt', 'kilt_peregrine', 'pendulum', 'krest_network'],
60
- // amplitude and kilt only share some common logic
61
- krest_network: ['krest_network'],
62
- kilt: ['kilt', 'kilt_peregrine'],
63
- nominationPool: ['polkadot', 'kusama', 'westend', 'alephTest', 'aleph', 'kate', 'vara_network', 'goldberg_testnet'],
64
- bifrost: ['bifrost', 'bifrost_testnet'],
65
- aleph: ['aleph', 'alephTest'],
66
- // A0 has distinct tokenomics
67
- ternoa: ['ternoa', 'ternoa_alphanet']
68
- };
69
55
  export const _STAKING_ERA_LENGTH_MAP = {
70
56
  // in hours
71
57
  alephTest: 24,
@@ -252,6 +238,7 @@ export const EVM_PASS_CONNECT_STATUS = {
252
238
  export const EVM_REFORMAT_DECIMALS = {
253
239
  acala: ['acala_evm', 'karura_evm']
254
240
  };
241
+ export const LATEST_CHAIN_DATA_FETCHING_INTERVAL = 30000;
255
242
 
256
243
  // TODO: review
257
244
  const TARGET_BRANCH = process.env.NODE_ENV !== 'production' ? 'koni-dev' : 'master';
@@ -57,7 +57,8 @@ export class SubstrateApi {
57
57
  const apiOption = {
58
58
  provider,
59
59
  typesBundle,
60
- registry: this.registry
60
+ registry: this.registry,
61
+ noInitWarn: true
61
62
  };
62
63
  if (this.metadata) {
63
64
  const metadata = this.metadata;
@@ -71,27 +72,31 @@ export class SubstrateApi {
71
72
  api = externalApiPromise;
72
73
  } else if (_API_OPTIONS_CHAIN_GROUP.acala.includes(this.chainSlug)) {
73
74
  api = new ApiPromise(acalaOptions({
74
- provider
75
+ provider,
76
+ noInitWarn: true
75
77
  }));
76
78
  } else if (_API_OPTIONS_CHAIN_GROUP.turing.includes(this.chainSlug)) {
77
79
  api = new ApiPromise({
78
80
  provider,
79
81
  rpc: oakRpc,
80
- types: oakTypes
82
+ types: oakTypes,
83
+ noInitWarn: true
81
84
  });
82
85
  } else if (_API_OPTIONS_CHAIN_GROUP.avail.includes(this.chainSlug)) {
83
86
  api = new ApiPromise({
84
87
  provider,
85
88
  rpc: availSpec.rpc,
86
89
  types: availSpec.types,
87
- signedExtensions: availSpec.signedExtensions
90
+ signedExtensions: availSpec.signedExtensions,
91
+ noInitWarn: true
88
92
  });
89
93
  } else if (_API_OPTIONS_CHAIN_GROUP.goldberg.includes(this.chainSlug)) {
90
94
  api = new ApiPromise({
91
95
  provider,
92
96
  rpc: goldbergSpec.rpc,
93
97
  types: goldbergSpec.types,
94
- signedExtensions: goldbergSpec.signedExtensions
98
+ signedExtensions: goldbergSpec.signedExtensions,
99
+ noInitWarn: true
95
100
  });
96
101
  } else {
97
102
  api = new ApiPromise(apiOption);
@@ -1,3 +1,4 @@
1
+ /// <reference types="node" />
1
2
  import { _AssetRef, _AssetType, _ChainAsset, _ChainInfo, _MultiChainAsset } from '@subwallet/chain-list/types';
2
3
  import { AssetSetting, ValidateNetworkResponse } from '@subwallet/extension-base/background/KoniTypes';
3
4
  import { MantaPrivateHandler } from '@subwallet/extension-base/services/chain-service/handler/manta/MantaPrivateHandler';
@@ -14,6 +15,7 @@ export declare class ChainService {
14
15
  private substrateChainHandler;
15
16
  private evmChainHandler;
16
17
  private mantaChainHandler;
18
+ refreshLatestChainDataTimeOut: NodeJS.Timer | undefined;
17
19
  get mantaPay(): MantaPrivateHandler | undefined;
18
20
  private chainInfoMapSubject;
19
21
  private chainStateMapSubject;
@@ -69,6 +71,12 @@ export declare class ChainService {
69
71
  deleteAssetsByChain(chainSlug: string): void;
70
72
  deleteCustomAssets(targetAssets: string[]): void;
71
73
  init(): Promise<void>;
74
+ checkLatestData(): void;
75
+ stopCheckLatestChainData(): void;
76
+ handleLatestProviderData(latestChainInfo: _ChainInfo[]): void;
77
+ handleLatestBlockedAssetRef(latestBlockedAssetRefList: string[]): void;
78
+ handleLatestPriceId(latestPriceIds: Record<string, string | null>): void;
79
+ handleLatestData(): void;
72
80
  private initApis;
73
81
  private initApiForChain;
74
82
  private destroyApiForChain;
@@ -77,7 +85,9 @@ export declare class ChainService {
77
85
  reconnectChain(chain: string): Promise<boolean>;
78
86
  disableChain(chainSlug: string): boolean;
79
87
  private checkExistedPredefinedChain;
80
- private fetchLatestData;
88
+ private fetchLatestChainData;
89
+ private fetchLatestPriceIdsData;
90
+ private fetchLatestBlockedAssetRef;
81
91
  private initChains;
82
92
  private initAssetRegistry;
83
93
  private updateChainStateMapSubscription;
@@ -3,15 +3,15 @@
3
3
 
4
4
  import { AssetLogoMap, AssetRefMap, ChainAssetMap, ChainInfoMap, ChainLogoMap, MultiChainAssetMap } from '@subwallet/chain-list';
5
5
  import { _AssetRefPath, _AssetType, _ChainStatus, _SubstrateChainType } from '@subwallet/chain-list/types';
6
- import { _ASSET_LOGO_MAP_SRC, _ASSET_REF_SRC, _CHAIN_ASSET_SRC, _CHAIN_INFO_SRC, _CHAIN_LOGO_MAP_SRC, _DEFAULT_ACTIVE_CHAINS, _MANTA_ZK_CHAIN_GROUP, _MULTI_CHAIN_ASSET_SRC, _ZK_ASSET_PREFIX } from '@subwallet/extension-base/services/chain-service/constants';
6
+ import { _DEFAULT_ACTIVE_CHAINS, _MANTA_ZK_CHAIN_GROUP, _ZK_ASSET_PREFIX, LATEST_CHAIN_DATA_FETCHING_INTERVAL } from '@subwallet/extension-base/services/chain-service/constants';
7
7
  import { EvmChainHandler } from '@subwallet/extension-base/services/chain-service/handler/EvmChainHandler';
8
8
  import { MantaPrivateHandler } from '@subwallet/extension-base/services/chain-service/handler/manta/MantaPrivateHandler';
9
9
  import { SubstrateChainHandler } from '@subwallet/extension-base/services/chain-service/handler/SubstrateChainHandler';
10
10
  import { _CHAIN_VALIDATION_ERROR } from '@subwallet/extension-base/services/chain-service/handler/types';
11
11
  import { _ChainConnectionStatus, _CUSTOM_PREFIX, _NFT_CONTRACT_STANDARDS, _SMART_CONTRACT_STANDARDS } from '@subwallet/extension-base/services/chain-service/types';
12
- import { _isAssetFungibleToken, _isChainEnabled, _isCustomAsset, _isCustomChain, _isCustomProvider, _isEqualContractAddress, _isEqualSmartContractAsset, _isMantaZkAsset, _isPureEvmChain, _isPureSubstrateChain, _parseAssetRefKey } from '@subwallet/extension-base/services/chain-service/utils';
12
+ import { _isAssetFungibleToken, _isChainEnabled, _isCustomAsset, _isCustomChain, _isCustomProvider, _isEqualContractAddress, _isEqualSmartContractAsset, _isMantaZkAsset, _isPureEvmChain, _isPureSubstrateChain, _parseAssetRefKey, randomizeProvider, updateLatestChainInfo } from '@subwallet/extension-base/services/chain-service/utils';
13
13
  import AssetSettingStore from '@subwallet/extension-base/stores/AssetSetting';
14
- import { MODULE_SUPPORT } from '@subwallet/extension-base/utils';
14
+ import { fetchStaticData, MODULE_SUPPORT } from '@subwallet/extension-base/utils';
15
15
  import { BehaviorSubject, Subject } from 'rxjs';
16
16
  import Web3 from 'web3';
17
17
  import { logger as createLogger } from '@polkadot/util/logger';
@@ -213,8 +213,9 @@ export class ChainService {
213
213
  getActiveChainInfos() {
214
214
  const result = {};
215
215
  Object.values(this.getChainStateMap()).forEach(chainState => {
216
- if (chainState.active) {
217
- result[chainState.slug] = this.getChainInfoByKey(chainState.slug);
216
+ const chainInfo = this.getChainInfoByKey(chainState.slug);
217
+ if (chainState.active && chainInfo && chainInfo.chainStatus === _ChainStatus.ACTIVE) {
218
+ result[chainState.slug] = chainInfo;
218
219
  }
219
220
  });
220
221
  return result;
@@ -395,9 +396,9 @@ export class ChainService {
395
396
  await this.eventService.waitDatabaseReady;
396
397
 
397
398
  // TODO: reconsider the flow of initiation
398
- const [latestAssetRefMap, latestMultiChainAssetMap] = await Promise.all([this.fetchLatestData(_ASSET_REF_SRC, AssetRefMap), this.fetchLatestData(_MULTI_CHAIN_ASSET_SRC, MultiChainAssetMap)]);
399
- this.multiChainAssetMapSubject.next(latestMultiChainAssetMap);
400
- this.dataMap.assetRefMap = latestAssetRefMap;
399
+ this.multiChainAssetMapSubject.next(MultiChainAssetMap);
400
+ const storedAssetRefMap = await this.dbService.getAssetRefMap();
401
+ this.dataMap.assetRefMap = storedAssetRefMap && Object.values(storedAssetRefMap).length > 0 ? storedAssetRefMap : AssetRefMap;
401
402
  await this.initChains();
402
403
  this.chainInfoMapSubject.next(this.getChainInfoMap());
403
404
  this.updateChainStateMapSubscription();
@@ -405,7 +406,71 @@ export class ChainService {
405
406
  this.xcmRefMapSubject.next(this.dataMap.assetRefMap);
406
407
  await this.initApis();
407
408
  await this.initAssetSettings();
409
+ this.checkLatestData();
408
410
  }
411
+ checkLatestData() {
412
+ clearInterval(this.refreshLatestChainDataTimeOut);
413
+ this.handleLatestData();
414
+ this.handleLatestData();
415
+ this.refreshLatestChainDataTimeOut = setInterval(this.handleLatestData.bind(this), LATEST_CHAIN_DATA_FETCHING_INTERVAL);
416
+ }
417
+ stopCheckLatestChainData() {
418
+ clearInterval(this.refreshLatestChainDataTimeOut);
419
+ }
420
+ handleLatestProviderData(latestChainInfo) {
421
+ try {
422
+ if (latestChainInfo && latestChainInfo.length > 0) {
423
+ const {
424
+ needUpdateChainApiList,
425
+ storedChainInfoList
426
+ } = updateLatestChainInfo(this.dataMap, latestChainInfo);
427
+ this.dbService.bulkUpdateChainStore(storedChainInfoList).catch(console.error);
428
+ this.updateChainSubscription();
429
+ needUpdateChainApiList.forEach(chainInfo => {
430
+ console.log('Updating chain API for', chainInfo.slug);
431
+ this.initApiForChain(chainInfo).catch(console.error);
432
+ });
433
+ this.logger.log('Finished updating latest RPC providers');
434
+ }
435
+ } catch (e) {
436
+ console.error('Error fetching latest chain data');
437
+ }
438
+ }
439
+ handleLatestBlockedAssetRef(latestBlockedAssetRefList) {
440
+ if (latestBlockedAssetRefList.length > 0) {
441
+ latestBlockedAssetRefList.forEach(blockedAssetRef => {
442
+ delete this.dataMap.assetRefMap[blockedAssetRef];
443
+ });
444
+ } else {
445
+ this.dataMap.assetRefMap = AssetRefMap;
446
+ }
447
+ this.dbService.setAssetRef(this.dataMap.assetRefMap).catch(console.error);
448
+ this.xcmRefMapSubject.next(this.dataMap.assetRefMap);
449
+ this.logger.log('Finished updating latest asset ref');
450
+ }
451
+ handleLatestPriceId(latestPriceIds) {
452
+ Object.entries(latestPriceIds).forEach(([slug, priceId]) => {
453
+ if (this.dataMap.assetRegistry[slug]) {
454
+ this.dataMap.assetRegistry[slug].priceId = priceId;
455
+ }
456
+ });
457
+ this.assetRegistrySubject.next(this.dataMap.assetRegistry);
458
+ this.eventService.emit('asset.updateState', '');
459
+ this.logger.log('Finished updating latest price IDs');
460
+ }
461
+ handleLatestData() {
462
+ this.fetchLatestChainData().then(latestChainInfo => {
463
+ this.handleLatestProviderData(latestChainInfo);
464
+ }).catch(console.error);
465
+ this.fetchLatestBlockedAssetRef().then(latestAssetRef => {
466
+ this.handleLatestBlockedAssetRef(latestAssetRef);
467
+ }).catch(console.error);
468
+
469
+ // this.fetchLatestPriceIdsData().then((latestPriceIds) => {
470
+ // this.handleLatestPriceId(latestPriceIds);
471
+ // }).catch(console.error);
472
+ }
473
+
409
474
  async initApis() {
410
475
  const chainInfoMap = this.getChainInfoMap();
411
476
  const chainStateMap = this.getChainStateMap();
@@ -561,8 +626,8 @@ export class ChainService {
561
626
  }
562
627
  return duplicatedSlug;
563
628
  }
564
- async fetchLatestData(src, defaultValue) {
565
- return Promise.resolve(defaultValue);
629
+ async fetchLatestChainData() {
630
+ return await fetchStaticData('chains');
566
631
  // try {
567
632
  // const timeout = new Promise((resolve) => {
568
633
  // const id = setTimeout(() => {
@@ -599,9 +664,16 @@ export class ChainService {
599
664
  // }
600
665
  }
601
666
 
667
+ // @ts-ignore
668
+ async fetchLatestPriceIdsData() {
669
+ return await fetchStaticData('chain-assets/price-map');
670
+ }
671
+ async fetchLatestBlockedAssetRef() {
672
+ return await fetchStaticData('chain-assets/disabled-xcm-channels');
673
+ }
602
674
  async initChains() {
603
675
  const storedChainSettings = await this.dbService.getAllChainStore();
604
- const latestChainInfoMap = await this.fetchLatestData(_CHAIN_INFO_SRC, ChainInfoMap);
676
+ const defaultChainInfoMap = ChainInfoMap;
605
677
  const storedChainSettingMap = {};
606
678
  storedChainSettings.forEach(chainStoredSetting => {
607
679
  storedChainSettingMap[chainStoredSetting.slug] = chainStoredSetting;
@@ -610,10 +682,13 @@ export class ChainService {
610
682
  const deprecatedChains = [];
611
683
  const deprecatedChainMap = {};
612
684
  if (storedChainSettings.length === 0) {
613
- this.dataMap.chainInfoMap = latestChainInfoMap;
614
- Object.values(latestChainInfoMap).forEach(chainInfo => {
685
+ this.dataMap.chainInfoMap = defaultChainInfoMap;
686
+ Object.values(defaultChainInfoMap).forEach(chainInfo => {
687
+ const {
688
+ providerKey
689
+ } = randomizeProvider(chainInfo.providers);
615
690
  this.dataMap.chainStateMap[chainInfo.slug] = {
616
- currentProvider: Object.keys(chainInfo.providers)[0],
691
+ currentProvider: providerKey,
617
692
  slug: chainInfo.slug,
618
693
  connectionStatus: _ChainConnectionStatus.DISCONNECTED,
619
694
  active: _DEFAULT_ACTIVE_CHAINS.includes(chainInfo.slug)
@@ -623,15 +698,15 @@ export class ChainService {
623
698
  newStorageData.push({
624
699
  ...chainInfo,
625
700
  active: _DEFAULT_ACTIVE_CHAINS.includes(chainInfo.slug),
626
- currentProvider: Object.keys(chainInfo.providers)[0]
701
+ currentProvider: providerKey
627
702
  });
628
703
  });
629
704
  } else {
630
- const mergedChainInfoMap = latestChainInfoMap;
705
+ const mergedChainInfoMap = defaultChainInfoMap;
631
706
  for (const [storedSlug, storedChainInfo] of Object.entries(storedChainSettingMap)) {
632
- const chainInfo = latestChainInfoMap[storedSlug];
707
+ const chainInfo = defaultChainInfoMap[storedSlug];
633
708
 
634
- // Network is existed on change list
709
+ // Network existed on change list
635
710
  // check predefined chains first, keep setting for providers and currentProvider
636
711
  if (chainInfo) {
637
712
  // Keep customer provider only
@@ -646,23 +721,27 @@ export class ChainService {
646
721
  }
647
722
  }
648
723
  mergedChainInfoMap[storedSlug].providers = providers;
649
-
650
- // Merge current provider
651
- let currentProvider = storedChainInfo.currentProvider;
652
- const providerValue = storedChainInfo.providers[currentProvider] || '';
653
- if (!providers[currentProvider]) {
654
- currentProvider = Object.keys(providers)[0];
655
- for (const [key, value] of Object.entries(providers)) {
656
- if (providerValue === value) {
657
- currentProvider = key;
658
- break;
659
- }
724
+ const {
725
+ providerKey
726
+ } = randomizeProvider(providers);
727
+ let selectedProvider = providerKey;
728
+ const storedProviderKey = storedChainInfo.currentProvider;
729
+ const storedProviderValue = storedChainInfo.providers[storedProviderKey] || '';
730
+ if (storedProviderValue !== null && storedProviderValue !== void 0 && storedProviderValue.startsWith('light') || storedProviderKey !== null && storedProviderKey !== void 0 && storedProviderKey.startsWith(_CUSTOM_PREFIX)) {
731
+ const savedProviderKey = Object.keys(providers).find(key => providers[key] === storedProviderValue);
732
+ if (savedProviderKey) {
733
+ selectedProvider = savedProviderKey;
660
734
  }
661
735
  }
736
+
737
+ // Merge current provider
738
+ // let currentProvider = storedChainInfo.currentProvider;
739
+ // const providerValue = storedChainInfo.providers[selectedProvider] || '';
740
+
662
741
  const hasProvider = Object.values(providers).length > 0;
663
742
  const canActive = hasProvider && chainInfo.chainStatus === _ChainStatus.ACTIVE;
664
743
  this.dataMap.chainStateMap[storedSlug] = {
665
- currentProvider: currentProvider,
744
+ currentProvider: selectedProvider,
666
745
  slug: storedSlug,
667
746
  connectionStatus: _ChainConnectionStatus.DISCONNECTED,
668
747
  active: canActive && storedChainInfo.active
@@ -670,13 +749,13 @@ export class ChainService {
670
749
  newStorageData.push({
671
750
  ...mergedChainInfoMap[storedSlug],
672
751
  active: canActive && storedChainInfo.active,
673
- currentProvider: currentProvider
752
+ currentProvider: selectedProvider
674
753
  });
675
754
  } else if (_isCustomChain(storedSlug)) {
676
755
  var _storedChainInfo$subs, _storedChainInfo$evmI;
677
756
  // only custom chains are left
678
757
  // check custom chain duplicated with predefined chain => merge into predefined chain
679
- const duplicatedDefaultSlug = this.checkExistedPredefinedChain(latestChainInfoMap, (_storedChainInfo$subs = storedChainInfo.substrateInfo) === null || _storedChainInfo$subs === void 0 ? void 0 : _storedChainInfo$subs.genesisHash, (_storedChainInfo$evmI = storedChainInfo.evmInfo) === null || _storedChainInfo$evmI === void 0 ? void 0 : _storedChainInfo$evmI.evmChainId);
758
+ const duplicatedDefaultSlug = this.checkExistedPredefinedChain(defaultChainInfoMap, (_storedChainInfo$subs = storedChainInfo.substrateInfo) === null || _storedChainInfo$subs === void 0 ? void 0 : _storedChainInfo$subs.genesisHash, (_storedChainInfo$evmI = storedChainInfo.evmInfo) === null || _storedChainInfo$evmI === void 0 ? void 0 : _storedChainInfo$evmI.evmChainId);
680
759
  if (duplicatedDefaultSlug.length > 0) {
681
760
  // merge custom chain with existed chain
682
761
  mergedChainInfoMap[duplicatedDefaultSlug].providers = {
@@ -701,6 +780,7 @@ export class ChainService {
701
780
  slug: storedSlug,
702
781
  name: storedChainInfo.name,
703
782
  providers: storedChainInfo.providers,
783
+ // TODO: review
704
784
  evmInfo: storedChainInfo.evmInfo,
705
785
  substrateInfo: storedChainInfo.substrateInfo,
706
786
  isTestnet: storedChainInfo.isTestnet,
@@ -710,6 +790,7 @@ export class ChainService {
710
790
  };
711
791
  this.dataMap.chainStateMap[storedSlug] = {
712
792
  currentProvider: storedChainInfo.currentProvider,
793
+ // TODO: review
713
794
  slug: storedSlug,
714
795
  connectionStatus: _ChainConnectionStatus.DISCONNECTED,
715
796
  active: storedChainInfo.active
@@ -717,7 +798,7 @@ export class ChainService {
717
798
  newStorageData.push({
718
799
  ...mergedChainInfoMap[storedSlug],
719
800
  active: storedChainInfo.active,
720
- currentProvider: storedChainInfo.currentProvider
801
+ currentProvider: storedChainInfo.currentProvider // TODO: review
721
802
  });
722
803
  }
723
804
  } else {
@@ -749,7 +830,7 @@ export class ChainService {
749
830
  }
750
831
  async initAssetRegistry(deprecatedCustomChainMap) {
751
832
  const storedAssetRegistry = await this.dbService.getAllAssetStore();
752
- const latestAssetRegistry = await this.fetchLatestData(_CHAIN_ASSET_SRC, ChainAssetMap);
833
+ const latestAssetRegistry = ChainAssetMap;
753
834
  const availableChains = Object.values(this.dataMap.chainInfoMap).filter(info => info.chainStatus === _ChainStatus.ACTIVE).map(chainInfo => chainInfo.slug);
754
835
 
755
836
  // Fill out zk assets from latestAssetRegistry if not supported
@@ -1199,9 +1280,11 @@ export class ChainService {
1199
1280
  }
1200
1281
  async stopAllChainApis() {
1201
1282
  await Promise.all([this.substrateChainHandler.sleep(), this.evmChainHandler.sleep()]);
1283
+ this.stopCheckLatestChainData();
1202
1284
  }
1203
1285
  async resumeAllChainApis() {
1204
1286
  await Promise.all([this.substrateChainHandler.wakeUp(), this.evmChainHandler.wakeUp()]);
1287
+ this.checkLatestData();
1205
1288
  }
1206
1289
  checkAndUpdateStatusMapForChain(chainSlug) {
1207
1290
  const substrateApiMap = this.getSubstrateApiMap();
@@ -1336,10 +1419,10 @@ export class ChainService {
1336
1419
  return this.assetSettingSubject;
1337
1420
  }
1338
1421
  async getChainLogoMap() {
1339
- return await this.fetchLatestData(_CHAIN_LOGO_MAP_SRC, ChainLogoMap);
1422
+ return Promise.resolve(ChainLogoMap);
1340
1423
  }
1341
1424
  async getAssetLogoMap() {
1342
- return await this.fetchLatestData(_ASSET_LOGO_MAP_SRC, AssetLogoMap);
1425
+ return Promise.resolve(AssetLogoMap);
1343
1426
  }
1344
1427
  resetWallet(resetAll) {
1345
1428
  if (resetAll) {
@@ -1,6 +1,7 @@
1
1
  import { _AssetRef, _AssetType, _ChainAsset, _ChainInfo, _MultiChainAsset } from '@subwallet/chain-list/types';
2
2
  import { BasicTokenInfo } from '@subwallet/extension-base/background/KoniTypes';
3
- import { _ChainState } from '@subwallet/extension-base/services/chain-service/types';
3
+ import { _ChainState, _DataMap } from '@subwallet/extension-base/services/chain-service/types';
4
+ import { IChain } from '@subwallet/extension-base/services/storage-service/databases';
4
5
  export declare function _isCustomChain(slug: string): boolean;
5
6
  export declare function _isCustomAsset(slug: string): boolean;
6
7
  export declare function _getCustomAssets(assetRegistry: Record<string, _ChainAsset>): Record<string, _ChainAsset>;
@@ -30,6 +31,7 @@ export declare function _getChainSubstrateAddressPrefix(chainInfo: _ChainInfo):
30
31
  export declare function _isChainSupportNativeNft(chainInfo: _ChainInfo): boolean;
31
32
  export declare function _isChainSupportEvmNft(chainInfo: _ChainInfo): boolean;
32
33
  export declare function _isChainSupportWasmNft(chainInfo: _ChainInfo): boolean;
34
+ export declare const _isSupportOrdinal: (chain: string) => boolean;
33
35
  export declare function _getNftTypesSupportedByChain(chainInfo: _ChainInfo): _AssetType[];
34
36
  export declare function _getTokenTypesSupportedByChain(chainInfo: _ChainInfo): _AssetType[];
35
37
  export declare function _getChainNativeTokenBasicInfo(chainInfo: _ChainInfo): BasicTokenInfo;
@@ -66,3 +68,11 @@ export declare function _generateCustomProviderKey(index: number): string;
66
68
  export declare const findChainInfoByHalfGenesisHash: (chainMap: Record<string, _ChainInfo>, halfGenesisHash?: string) => _ChainInfo | null;
67
69
  export declare const findChainInfoByChainId: (chainMap: Record<string, _ChainInfo>, chainId?: number) => _ChainInfo | null;
68
70
  export declare function _isMantaZkAsset(chainAsset: _ChainAsset): boolean;
71
+ export declare function randomizeProvider(providers: Record<string, string>, excludedKeys?: string[]): {
72
+ providerKey: string;
73
+ providerValue: string;
74
+ };
75
+ export declare function updateLatestChainInfo(currentDataMap: _DataMap, latestChainInfoList: _ChainInfo[]): {
76
+ storedChainInfoList: IChain[];
77
+ needUpdateChainApiList: _ChainInfo[];
78
+ };
@@ -1,7 +1,7 @@
1
1
  // Copyright 2019-2022 @subwallet/extension-base
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- import { _AssetRefPath, _AssetType, _SubstrateChainType } from '@subwallet/chain-list/types';
4
+ import { _AssetRefPath, _AssetType, _ChainStatus, _SubstrateChainType } from '@subwallet/chain-list/types';
5
5
  import { _MANTA_ZK_CHAIN_GROUP, _ZK_ASSET_PREFIX } from '@subwallet/extension-base/services/chain-service/constants';
6
6
  import { _CUSTOM_PREFIX, _SMART_CONTRACT_STANDARDS } from '@subwallet/extension-base/services/chain-service/types';
7
7
  import { isEthereumAddress } from '@polkadot/util-crypto';
@@ -92,7 +92,7 @@ export function _getTokenMinAmount(tokenInfo) {
92
92
  return tokenInfo.minAmount || '0';
93
93
  }
94
94
  export function _isChainEvmCompatible(chainInfo) {
95
- return chainInfo.evmInfo !== undefined && chainInfo.evmInfo !== null;
95
+ return !!chainInfo.evmInfo;
96
96
  }
97
97
  export function _isNativeToken(tokenInfo) {
98
98
  return tokenInfo.assetType === _AssetType.NATIVE;
@@ -147,6 +147,10 @@ export function _isChainSupportWasmNft(chainInfo) {
147
147
  var _chainInfo$substrateI8, _chainInfo$substrateI9;
148
148
  return ((_chainInfo$substrateI8 = chainInfo.substrateInfo) === null || _chainInfo$substrateI8 === void 0 ? void 0 : (_chainInfo$substrateI9 = _chainInfo$substrateI8.supportSmartContract) === null || _chainInfo$substrateI9 === void 0 ? void 0 : _chainInfo$substrateI9.includes(_AssetType.PSP34)) || false;
149
149
  }
150
+ export const _isSupportOrdinal = chain => {
151
+ const chains = ['polkadot', 'astar', 'bifrost_dot', 'moonbeam'];
152
+ return chains.includes(chain);
153
+ };
150
154
  export function _getNftTypesSupportedByChain(chainInfo) {
151
155
  const result = [];
152
156
  if (chainInfo.substrateInfo && chainInfo.substrateInfo.supportSmartContract) {
@@ -358,4 +362,69 @@ export const findChainInfoByChainId = (chainMap, chainId) => {
358
362
  };
359
363
  export function _isMantaZkAsset(chainAsset) {
360
364
  return _MANTA_ZK_CHAIN_GROUP.includes(chainAsset.originChain) && chainAsset.symbol.startsWith(_ZK_ASSET_PREFIX);
365
+ }
366
+ export function randomizeProvider(providers, excludedKeys) {
367
+ if (Object.keys(providers).length === 0) {
368
+ return {
369
+ providerKey: '',
370
+ providerValue: ''
371
+ };
372
+ }
373
+ let isValid = false;
374
+ let selectedProviderKey = '';
375
+ let selectedProviderValue = '';
376
+ while (!isValid) {
377
+ var _selectedProviderValu, _selectedProviderKey;
378
+ const randomProvider = Math.floor(Math.random() * Object.keys(providers).length);
379
+ selectedProviderKey = Object.keys(providers)[randomProvider];
380
+ selectedProviderValue = providers[selectedProviderKey];
381
+ if (!((_selectedProviderValu = selectedProviderValue) !== null && _selectedProviderValu !== void 0 && _selectedProviderValu.startsWith('light')) && !((_selectedProviderKey = selectedProviderKey) !== null && _selectedProviderKey !== void 0 && _selectedProviderKey.startsWith(_CUSTOM_PREFIX)) && !(excludedKeys !== null && excludedKeys !== void 0 && excludedKeys.includes(selectedProviderKey))) {
382
+ // if it's light client, then re-randomize
383
+ isValid = true;
384
+ }
385
+ }
386
+ return {
387
+ providerKey: selectedProviderKey,
388
+ providerValue: selectedProviderValue
389
+ };
390
+ }
391
+ export function updateLatestChainInfo(currentDataMap, latestChainInfoList) {
392
+ const currentChainInfoMap = currentDataMap.chainInfoMap;
393
+ const currentChainStateMap = currentDataMap.chainStateMap;
394
+ const storedChainInfoList = [];
395
+ const needUpdateChainApiList = [];
396
+ latestChainInfoList.forEach(latestChainInfo => {
397
+ const currentChainInfo = currentChainInfoMap[latestChainInfo.slug];
398
+ const currentChainState = currentChainStateMap[latestChainInfo.slug];
399
+ const currentChainProviderValue = currentChainInfo === null || currentChainInfo === void 0 ? void 0 : currentChainInfo.providers[currentChainState === null || currentChainState === void 0 ? void 0 : currentChainState.currentProvider];
400
+ if (currentChainInfo && currentChainState) {
401
+ const preservedProvider = {};
402
+ Object.entries(currentChainInfo.providers).forEach(([providerKey, providerValue]) => {
403
+ if (providerValue !== null && providerValue !== void 0 && providerValue.startsWith('light') || providerKey !== null && providerKey !== void 0 && providerKey.startsWith(_CUSTOM_PREFIX)) {
404
+ preservedProvider[providerKey] = providerValue;
405
+ }
406
+ });
407
+ currentChainInfo.providers = {
408
+ ...latestChainInfo.providers,
409
+ ...preservedProvider
410
+ };
411
+ const currentProviderNotFound = !Object.keys(currentChainInfo.providers).includes(currentChainState.currentProvider);
412
+ const currentProviderUpdated = Object.keys(currentChainInfo.providers).includes(currentChainState.currentProvider) && !Object.values(currentChainInfo.providers).includes(currentChainProviderValue);
413
+ if (currentChainInfo.chainStatus === _ChainStatus.ACTIVE && (currentProviderNotFound || currentProviderUpdated)) {
414
+ const {
415
+ providerKey
416
+ } = randomizeProvider(currentChainInfo.providers);
417
+ currentChainState.currentProvider = providerKey;
418
+ needUpdateChainApiList.push(currentChainInfo);
419
+ }
420
+ storedChainInfoList.push({
421
+ ...currentChainInfo,
422
+ ...currentChainState
423
+ });
424
+ }
425
+ });
426
+ return {
427
+ storedChainInfoList,
428
+ needUpdateChainApiList
429
+ };
361
430
  }