@subwallet/extension-base 1.1.31-1 → 1.1.31-beta.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 (305) hide show
  1. package/background/KoniTypes.d.ts +111 -69
  2. package/background/KoniTypes.js +19 -13
  3. package/background/errors/TransactionError.js +9 -0
  4. package/cjs/background/KoniTypes.js +20 -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 +17 -15
  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 +46 -0
  24. package/cjs/koni/background/cron.js +11 -1
  25. package/cjs/koni/background/handlers/Extension.js +362 -69
  26. package/cjs/koni/background/handlers/State.js +51 -3
  27. package/cjs/koni/background/handlers/index.js +4 -2
  28. package/cjs/koni/background/subscription.js +95 -37
  29. package/cjs/services/campaign-service/index.js +9 -6
  30. package/cjs/services/chain-service/constants.js +2 -16
  31. package/cjs/services/chain-service/index.js +3 -2
  32. package/cjs/services/chain-service/utils.js +7 -1
  33. package/cjs/services/earning-service/constants/chains.js +29 -0
  34. package/cjs/services/earning-service/constants/index.js +27 -0
  35. package/cjs/services/earning-service/constants/step.js +18 -0
  36. package/cjs/services/earning-service/handlers/base.js +259 -0
  37. package/cjs/services/earning-service/handlers/index.js +60 -0
  38. package/cjs/services/earning-service/handlers/lending/base.js +20 -0
  39. package/cjs/services/earning-service/handlers/lending/index.js +13 -0
  40. package/cjs/services/earning-service/handlers/lending/interlay.js +191 -0
  41. package/cjs/services/earning-service/handlers/liquid-staking/acala.js +239 -0
  42. package/cjs/services/earning-service/handlers/liquid-staking/base.js +43 -0
  43. package/cjs/services/earning-service/handlers/liquid-staking/bifrost.js +297 -0
  44. package/cjs/services/earning-service/handlers/liquid-staking/index.js +34 -0
  45. package/cjs/services/earning-service/handlers/liquid-staking/parallel.js +226 -0
  46. package/cjs/services/earning-service/handlers/liquid-staking/stella-swap.js +395 -0
  47. package/cjs/services/earning-service/handlers/native-staking/amplitude.js +384 -0
  48. package/cjs/services/earning-service/handlers/native-staking/astar.js +461 -0
  49. package/cjs/services/earning-service/handlers/native-staking/base-para.js +146 -0
  50. package/cjs/services/earning-service/handlers/native-staking/base.js +159 -0
  51. package/cjs/services/earning-service/handlers/native-staking/index.js +34 -0
  52. package/cjs/services/earning-service/handlers/native-staking/para-chain.js +385 -0
  53. package/cjs/services/earning-service/handlers/native-staking/relay-chain.js +558 -0
  54. package/cjs/services/earning-service/handlers/nomination-pool/index.js +560 -0
  55. package/cjs/services/earning-service/handlers/special.js +503 -0
  56. package/cjs/services/earning-service/service.js +387 -0
  57. package/cjs/services/earning-service/utils/index.js +128 -0
  58. package/cjs/services/event-service/index.js +4 -0
  59. package/cjs/services/keyring-service/index.js +14 -2
  60. package/cjs/services/migration-service/scripts/DeleteEarningData.js +21 -0
  61. package/cjs/services/migration-service/scripts/EnableEarningChains.js +21 -0
  62. package/cjs/services/migration-service/scripts/MigrateEthProvider.js +17 -0
  63. package/cjs/services/migration-service/scripts/MigrateLedgerAccount.js +1 -1
  64. package/cjs/services/migration-service/scripts/MigratePioneerProvider.js +17 -0
  65. package/cjs/services/migration-service/scripts/MigrateProvider.js +29 -0
  66. package/cjs/services/migration-service/scripts/MigrateTransactionHistory.js +1 -1
  67. package/cjs/services/migration-service/scripts/databases/MigrateEarningHistory.js +21 -0
  68. package/cjs/services/migration-service/scripts/databases/MigrateEarningVersion.js +21 -0
  69. package/cjs/services/migration-service/scripts/index.js +7 -1
  70. package/cjs/services/mint-campaign-service/campaigns/UnlockDotCampaign.js +149 -0
  71. package/cjs/services/mint-campaign-service/campaigns/index.js +13 -0
  72. package/cjs/services/mint-campaign-service/constants.js +11 -0
  73. package/cjs/services/mint-campaign-service/index.js +18 -0
  74. package/cjs/services/notification-service/NotificationService.js +1 -1
  75. package/cjs/services/storage-service/DatabaseService.js +51 -0
  76. package/cjs/services/storage-service/databases/index.js +4 -0
  77. package/cjs/services/storage-service/db-stores/NominatorMetadata.js +3 -3
  78. package/cjs/services/storage-service/db-stores/YieldPoolStore.js +36 -0
  79. package/cjs/services/storage-service/db-stores/YieldPositionStore.js +65 -0
  80. package/cjs/services/storage-service/index.js +241 -0
  81. package/cjs/services/subscan-service/index.js +16 -0
  82. package/cjs/services/transaction-service/event-parser/index.js +58 -0
  83. package/cjs/services/transaction-service/helpers/index.js +3 -1
  84. package/cjs/services/transaction-service/index.js +231 -75
  85. package/cjs/services/transaction-service/utils.js +1 -0
  86. package/cjs/types/campaigns/index.js +16 -0
  87. package/cjs/types/campaigns/unlock-dot.js +1 -0
  88. package/cjs/types/index.js +44 -0
  89. package/cjs/types/ordinal.js +1 -0
  90. package/cjs/types/transaction.js +1 -0
  91. package/cjs/types/yield/actions/index.js +27 -0
  92. package/cjs/types/yield/actions/join/index.js +38 -0
  93. package/cjs/types/yield/actions/join/step.js +47 -0
  94. package/cjs/types/yield/actions/join/submit.js +1 -0
  95. package/cjs/types/yield/actions/join/validate.js +16 -0
  96. package/cjs/types/yield/actions/others.js +1 -0
  97. package/cjs/types/yield/index.js +27 -0
  98. package/cjs/types/yield/info/account/index.js +49 -0
  99. package/cjs/types/yield/info/account/info.js +1 -0
  100. package/cjs/types/yield/info/account/reward.js +1 -0
  101. package/cjs/types/yield/info/account/target.js +32 -0
  102. package/cjs/types/yield/info/account/unstake.js +27 -0
  103. package/cjs/types/yield/info/base.js +41 -0
  104. package/cjs/types/yield/info/chain/index.js +27 -0
  105. package/cjs/types/yield/info/chain/info.js +1 -0
  106. package/cjs/types/yield/info/chain/target.js +1 -0
  107. package/cjs/types/yield/info/index.js +49 -0
  108. package/cjs/types/yield/info/pallet.js +15 -0
  109. package/cjs/types.js +1 -0
  110. package/cjs/utils/address.js +34 -0
  111. package/cjs/utils/fetchStaticData.js +2 -1
  112. package/cjs/utils/index.js +89 -1
  113. package/cjs/utils/keyring.js +57 -0
  114. package/cjs/utils/number.js +3 -1
  115. package/cjs/utils/object.js +12 -0
  116. package/constants/index.d.ts +6 -1
  117. package/constants/index.js +6 -1
  118. package/koni/api/nft/config.js +33 -23
  119. package/koni/api/nft/index.js +15 -1
  120. package/koni/api/nft/nft.js +2 -23
  121. package/koni/api/nft/ordinal_nft/constants.d.ts +9 -0
  122. package/koni/api/nft/ordinal_nft/constants.js +12 -0
  123. package/koni/api/nft/ordinal_nft/index.d.ts +8 -0
  124. package/koni/api/nft/ordinal_nft/index.js +114 -0
  125. package/koni/api/nft/ordinal_nft/utils.d.ts +2 -0
  126. package/koni/api/nft/ordinal_nft/utils.js +33 -0
  127. package/koni/api/staking/bonding/amplitude.js +11 -9
  128. package/koni/api/staking/bonding/astar.js +9 -8
  129. package/koni/api/staking/bonding/index.d.ts +1 -1
  130. package/koni/api/staking/bonding/index.js +5 -1
  131. package/koni/api/staking/bonding/paraChain.js +12 -10
  132. package/koni/api/staking/bonding/relayChain.d.ts +2 -2
  133. package/koni/api/staking/bonding/relayChain.js +33 -30
  134. package/koni/api/staking/bonding/utils.d.ts +15 -38
  135. package/koni/api/staking/bonding/utils.js +85 -69
  136. package/koni/api/staking/index.js +2 -1
  137. package/koni/api/staking/paraChain.js +7 -6
  138. package/koni/api/staking/relayChain.js +4 -3
  139. package/koni/api/yield/helper/utils.d.ts +10 -0
  140. package/koni/api/yield/helper/utils.js +32 -0
  141. package/koni/background/cron.d.ts +1 -0
  142. package/koni/background/cron.js +12 -2
  143. package/koni/background/handlers/Extension.d.ts +17 -1
  144. package/koni/background/handlers/Extension.js +321 -30
  145. package/koni/background/handlers/State.d.ts +18 -2
  146. package/koni/background/handlers/State.js +50 -3
  147. package/koni/background/handlers/index.js +4 -2
  148. package/koni/background/subscription.d.ts +6 -1
  149. package/koni/background/subscription.js +97 -38
  150. package/package.json +316 -3
  151. package/services/campaign-service/index.js +9 -6
  152. package/services/chain-service/constants.d.ts +0 -11
  153. package/services/chain-service/constants.js +1 -14
  154. package/services/chain-service/index.js +3 -2
  155. package/services/chain-service/utils.d.ts +1 -0
  156. package/services/chain-service/utils.js +5 -1
  157. package/services/earning-service/constants/abis/compound_finance_v2_abi.json +1235 -0
  158. package/services/earning-service/constants/abis/st_liquid_token_abi.json +1355 -0
  159. package/services/earning-service/constants/chains.d.ts +14 -0
  160. package/services/earning-service/constants/chains.js +21 -0
  161. package/services/earning-service/constants/index.d.ts +2 -0
  162. package/services/earning-service/constants/index.js +5 -0
  163. package/services/earning-service/constants/step.d.ts +3 -0
  164. package/services/earning-service/constants/step.js +10 -0
  165. package/services/earning-service/handlers/base.d.ts +112 -0
  166. package/services/earning-service/handlers/base.js +253 -0
  167. package/services/earning-service/handlers/index.d.ts +5 -0
  168. package/services/earning-service/handlers/index.js +8 -0
  169. package/services/earning-service/handlers/lending/base.d.ts +6 -0
  170. package/services/earning-service/handlers/lending/base.js +12 -0
  171. package/services/earning-service/handlers/lending/index.d.ts +1 -0
  172. package/services/earning-service/handlers/lending/index.js +4 -0
  173. package/services/earning-service/handlers/lending/interlay.d.ts +24 -0
  174. package/services/earning-service/handlers/lending/interlay.js +183 -0
  175. package/services/earning-service/handlers/liquid-staking/acala.d.ts +27 -0
  176. package/services/earning-service/handlers/liquid-staking/acala.js +231 -0
  177. package/services/earning-service/handlers/liquid-staking/base.d.ts +9 -0
  178. package/services/earning-service/handlers/liquid-staking/base.js +35 -0
  179. package/services/earning-service/handlers/liquid-staking/bifrost.d.ts +46 -0
  180. package/services/earning-service/handlers/liquid-staking/bifrost.js +286 -0
  181. package/services/earning-service/handlers/liquid-staking/index.d.ts +4 -0
  182. package/services/earning-service/handlers/liquid-staking/index.js +7 -0
  183. package/services/earning-service/handlers/liquid-staking/parallel.d.ts +26 -0
  184. package/services/earning-service/handlers/liquid-staking/parallel.js +218 -0
  185. package/services/earning-service/handlers/liquid-staking/stella-swap.d.ts +34 -0
  186. package/services/earning-service/handlers/liquid-staking/stella-swap.js +385 -0
  187. package/services/earning-service/handlers/native-staking/amplitude.d.ts +22 -0
  188. package/services/earning-service/handlers/native-staking/amplitude.js +375 -0
  189. package/services/earning-service/handlers/native-staking/astar.d.ts +19 -0
  190. package/services/earning-service/handlers/native-staking/astar.js +451 -0
  191. package/services/earning-service/handlers/native-staking/base-para.d.ts +11 -0
  192. package/services/earning-service/handlers/native-staking/base-para.js +138 -0
  193. package/services/earning-service/handlers/native-staking/base.d.ts +21 -0
  194. package/services/earning-service/handlers/native-staking/base.js +150 -0
  195. package/services/earning-service/handlers/native-staking/index.d.ts +4 -0
  196. package/services/earning-service/handlers/native-staking/index.js +7 -0
  197. package/services/earning-service/handlers/native-staking/para-chain.d.ts +15 -0
  198. package/services/earning-service/handlers/native-staking/para-chain.js +377 -0
  199. package/services/earning-service/handlers/native-staking/relay-chain.d.ts +21 -0
  200. package/services/earning-service/handlers/native-staking/relay-chain.js +549 -0
  201. package/services/earning-service/handlers/nomination-pool/index.d.ts +36 -0
  202. package/services/earning-service/handlers/nomination-pool/index.js +550 -0
  203. package/services/earning-service/handlers/special.d.ts +65 -0
  204. package/services/earning-service/handlers/special.js +495 -0
  205. package/services/earning-service/service.d.ts +45 -0
  206. package/services/earning-service/service.js +379 -0
  207. package/services/earning-service/utils/index.d.ts +18 -0
  208. package/services/earning-service/utils/index.js +112 -0
  209. package/services/event-service/index.d.ts +1 -0
  210. package/services/event-service/index.js +4 -0
  211. package/services/event-service/types.d.ts +8 -0
  212. package/services/keyring-service/index.d.ts +2 -1
  213. package/services/keyring-service/index.js +14 -2
  214. package/services/migration-service/scripts/DeleteEarningData.d.ts +4 -0
  215. package/services/migration-service/scripts/DeleteEarningData.js +13 -0
  216. package/services/migration-service/scripts/EnableEarningChains.d.ts +4 -0
  217. package/services/migration-service/scripts/EnableEarningChains.js +13 -0
  218. package/services/migration-service/scripts/MigrateLedgerAccount.js +1 -1
  219. package/services/migration-service/scripts/MigrateTransactionHistory.js +1 -1
  220. package/services/migration-service/scripts/databases/MigrateEarningHistory.d.ts +4 -0
  221. package/services/migration-service/scripts/databases/MigrateEarningHistory.js +13 -0
  222. package/services/migration-service/scripts/databases/MigrateEarningVersion.d.ts +4 -0
  223. package/services/migration-service/scripts/databases/MigrateEarningVersion.js +13 -0
  224. package/services/migration-service/scripts/index.js +7 -1
  225. package/services/mint-campaign-service/campaigns/UnlockDotCampaign.d.ts +13 -0
  226. package/services/mint-campaign-service/campaigns/UnlockDotCampaign.js +139 -0
  227. package/services/mint-campaign-service/campaigns/index.d.ts +1 -0
  228. package/services/mint-campaign-service/campaigns/index.js +4 -0
  229. package/services/mint-campaign-service/constants.d.ts +1 -0
  230. package/services/mint-campaign-service/constants.js +4 -0
  231. package/services/mint-campaign-service/index.d.ts +7 -0
  232. package/services/mint-campaign-service/index.js +11 -0
  233. package/services/notification-service/NotificationService.js +1 -1
  234. package/services/storage-service/DatabaseService.d.ts +18 -1
  235. package/services/storage-service/DatabaseService.js +51 -0
  236. package/services/storage-service/databases/index.d.ts +3 -1
  237. package/services/storage-service/databases/index.js +4 -0
  238. package/services/storage-service/db-stores/NominatorMetadata.js +3 -3
  239. package/services/storage-service/db-stores/YieldPoolStore.d.ts +10 -0
  240. package/services/storage-service/db-stores/YieldPoolStore.js +28 -0
  241. package/services/storage-service/db-stores/YieldPositionStore.d.ts +9 -0
  242. package/services/storage-service/db-stores/YieldPositionStore.js +57 -0
  243. package/services/subscan-service/index.d.ts +3 -2
  244. package/services/subscan-service/index.js +15 -0
  245. package/services/subscan-service/types.d.ts +20 -0
  246. package/services/transaction-service/event-parser/index.d.ts +3 -1
  247. package/services/transaction-service/event-parser/index.js +57 -1
  248. package/services/transaction-service/helpers/index.js +3 -1
  249. package/services/transaction-service/index.d.ts +4 -15
  250. package/services/transaction-service/index.js +229 -73
  251. package/services/transaction-service/types.d.ts +2 -0
  252. package/services/transaction-service/utils.js +1 -0
  253. package/types/campaigns/index.d.ts +1 -0
  254. package/types/campaigns/index.js +4 -0
  255. package/types/campaigns/unlock-dot.d.ts +71 -0
  256. package/types/campaigns/unlock-dot.js +1 -0
  257. package/types/index.d.ts +5 -0
  258. package/types/index.js +5 -1
  259. package/types/ordinal.d.ts +69 -0
  260. package/types/ordinal.js +1 -0
  261. package/types/transaction.d.ts +3 -0
  262. package/types/transaction.js +1 -0
  263. package/types/yield/actions/index.d.ts +2 -0
  264. package/types/yield/actions/index.js +5 -0
  265. package/types/yield/actions/join/index.d.ts +3 -0
  266. package/types/yield/actions/join/index.js +6 -0
  267. package/types/yield/actions/join/step.d.ts +95 -0
  268. package/types/yield/actions/join/step.js +46 -0
  269. package/types/yield/actions/join/submit.d.ts +57 -0
  270. package/types/yield/actions/join/submit.js +1 -0
  271. package/types/yield/actions/join/validate.d.ts +18 -0
  272. package/types/yield/actions/join/validate.js +10 -0
  273. package/types/yield/actions/others.d.ts +85 -0
  274. package/types/yield/actions/others.js +1 -0
  275. package/types/yield/index.d.ts +2 -0
  276. package/types/yield/index.js +5 -0
  277. package/types/yield/info/account/index.d.ts +4 -0
  278. package/types/yield/info/account/index.js +7 -0
  279. package/types/yield/info/account/info.d.ts +92 -0
  280. package/types/yield/info/account/info.js +1 -0
  281. package/types/yield/info/account/reward.d.ts +45 -0
  282. package/types/yield/info/account/reward.js +1 -0
  283. package/types/yield/info/account/target.d.ts +43 -0
  284. package/types/yield/info/account/target.js +27 -0
  285. package/types/yield/info/account/unstake.d.ts +31 -0
  286. package/types/yield/info/account/unstake.js +22 -0
  287. package/types/yield/info/base.d.ts +45 -0
  288. package/types/yield/info/base.js +36 -0
  289. package/types/yield/info/chain/index.d.ts +2 -0
  290. package/types/yield/info/chain/index.js +5 -0
  291. package/types/yield/info/chain/info.d.ts +251 -0
  292. package/types/yield/info/chain/info.js +1 -0
  293. package/types/yield/info/chain/target.d.ts +37 -0
  294. package/types/yield/info/chain/target.js +1 -0
  295. package/types/yield/info/index.d.ts +4 -0
  296. package/types/yield/info/index.js +7 -0
  297. package/types/yield/info/pallet.d.ts +143 -0
  298. package/types/yield/info/pallet.js +9 -0
  299. package/utils/fetchStaticData.js +2 -1
  300. package/utils/index.d.ts +5 -0
  301. package/utils/index.js +53 -1
  302. package/utils/number.d.ts +1 -1
  303. package/utils/number.js +1 -1
  304. package/utils/object.d.ts +1 -0
  305. package/utils/object.js +6 -0
@@ -15,12 +15,13 @@ import { resolveAzeroAddressToDomain, resolveAzeroDomainToAddress } from '@subwa
15
15
  import { parseSubstrateTransaction } from '@subwallet/extension-base/koni/api/dotsama/parseTransaction';
16
16
  import { checkReferenceCount, checkSupportTransfer, createTransferExtrinsic } from '@subwallet/extension-base/koni/api/dotsama/transfer';
17
17
  import { getNftTransferExtrinsic, isRecipientSelf } from '@subwallet/extension-base/koni/api/nft/transfer';
18
- import { getBondingExtrinsic, getCancelWithdrawalExtrinsic, getClaimRewardExtrinsic, getNominationPoolsInfo, getUnbondingExtrinsic, getValidatorsInfo, getWithdrawalExtrinsic, validateBondingCondition, validateUnbondingCondition } from '@subwallet/extension-base/koni/api/staking/bonding';
18
+ import { getBondingExtrinsic, getCancelWithdrawalExtrinsic, getClaimRewardExtrinsic, getNominationPoolsInfo, getUnbondingExtrinsic, getValidatorsInfo, validateBondingCondition, validateUnbondingCondition } from '@subwallet/extension-base/koni/api/staking/bonding';
19
19
  import { getTuringCancelCompoundingExtrinsic, getTuringCompoundExtrinsic } from '@subwallet/extension-base/koni/api/staking/bonding/paraChain';
20
20
  import { getPoolingBondingExtrinsic, getPoolingUnbondingExtrinsic, validatePoolBondingCondition, validateRelayUnbondingCondition } from '@subwallet/extension-base/koni/api/staking/bonding/relayChain';
21
21
  import { getERC20TransactionObject, getERC721Transaction, getEVMTransactionObject } from '@subwallet/extension-base/koni/api/tokens/evm/transfer';
22
22
  import { getPSP34TransferExtrinsic } from '@subwallet/extension-base/koni/api/tokens/wasm';
23
23
  import { createXcmExtrinsic } from '@subwallet/extension-base/koni/api/xcm';
24
+ import { YIELD_EXTRINSIC_TYPES } from '@subwallet/extension-base/koni/api/yield/helper/utils';
24
25
  import { _API_OPTIONS_CHAIN_GROUP, _DEFAULT_MANTA_ZK_CHAIN, _MANTA_ZK_CHAIN_GROUP, _ZK_ASSET_PREFIX } from '@subwallet/extension-base/services/chain-service/constants';
25
26
  import { _ChainConnectionStatus } from '@subwallet/extension-base/services/chain-service/types';
26
27
  import { _getChainNativeTokenBasicInfo, _getContractAddressOfToken, _getEvmChainId, _getSubstrateGenesisHash, _getTokenMinAmount, _isAssetSmartContractNft, _isChainEvmCompatible, _isCustomAsset, _isLocalToken, _isMantaZkAsset, _isNativeToken, _isTokenEvmSmartContract, _isTokenTransferredByEvm } from '@subwallet/extension-base/services/chain-service/utils';
@@ -28,6 +29,7 @@ import { EXTENSION_REQUEST_URL } from '@subwallet/extension-base/services/reques
28
29
  import { DEFAULT_AUTO_LOCK_TIME } from '@subwallet/extension-base/services/setting-service/constants';
29
30
  import { WALLET_CONNECT_EIP155_NAMESPACE } from '@subwallet/extension-base/services/wallet-connect-service/constants';
30
31
  import { isProposalExpired, isSupportWalletConnectChain, isSupportWalletConnectNamespace } from '@subwallet/extension-base/services/wallet-connect-service/helpers';
32
+ import { YieldPoolType } from '@subwallet/extension-base/types';
31
33
  import { convertSubjectInfoToAddresses, isSameAddress, reformatAddress, uniqueStringArray } from '@subwallet/extension-base/utils';
32
34
  import { createTransactionFromRLP, recalculateGasPrice, signatureToHex } from '@subwallet/extension-base/utils/eth';
33
35
  import { parseContractInput, parseEvmRlp } from '@subwallet/extension-base/utils/eth/parseTransaction';
@@ -468,6 +470,7 @@ export default class KoniExtension {
468
470
  const cb = createSubscription(id, port);
469
471
  const keyringService = this.#koniState.keyringService;
470
472
  await this.#koniState.eventService.waitAccountReady;
473
+ await this.#koniState.eventService.waitInjectReady;
471
474
  const currentAccount = keyringService.currentAccount;
472
475
  const transformedAccounts = transformAccounts(keyringService.accounts);
473
476
  const responseData = {
@@ -1022,6 +1025,9 @@ export default class KoniExtension {
1022
1025
  getCrowdloan(reset) {
1023
1026
  return this.#koniState.getCrowdloan(reset);
1024
1027
  }
1028
+ getCrowdloanContributions(request) {
1029
+ return this.#koniState.getCrowdloanContributions(request);
1030
+ }
1025
1031
  subscribeCrowdloan(id, port) {
1026
1032
  const cb = createSubscription(id, port);
1027
1033
  const crowdloanSubscription = this.#koniState.subscribeCrowdloan().subscribe({
@@ -1910,12 +1916,22 @@ export default class KoniExtension {
1910
1916
  token
1911
1917
  }, id, port) {
1912
1918
  const cb = createSubscription(id, port);
1913
- const [unsub, currentFreeBalance] = await this.#koniState.balanceService.subscribeTokenFreeBalance(address, networkKey, token, cb);
1919
+ const convertData = data => {
1920
+ return {
1921
+ ...data,
1922
+ id
1923
+ };
1924
+ };
1925
+ const _cb = data => {
1926
+ // eslint-disable-next-line node/no-callback-literal
1927
+ cb(convertData(data));
1928
+ };
1929
+ const [unsub, currentFreeBalance] = await this.#koniState.balanceService.subscribeTokenFreeBalance(address, networkKey, token, _cb);
1914
1930
  this.createUnsubscriptionHandle(id, unsub);
1915
1931
  port.onDisconnect.addListener(() => {
1916
1932
  this.cancelSubscription(id);
1917
1933
  });
1918
- return currentFreeBalance;
1934
+ return convertData(currentFreeBalance);
1919
1935
  }
1920
1936
  async transferCheckReferenceCount({
1921
1937
  address,
@@ -2530,36 +2546,18 @@ export default class KoniExtension {
2530
2546
  chainType: ChainType.SUBSTRATE
2531
2547
  });
2532
2548
  }
2533
- async submitStakeWithdrawal(inputData) {
2534
- const {
2535
- chain,
2536
- nominatorMetadata,
2537
- validatorAddress
2538
- } = inputData;
2539
- if (!nominatorMetadata) {
2540
- return this.#koniState.transactionService.generateBeforeHandleResponseErrors([new TransactionError(BasicTxErrorType.INVALID_PARAMS)]);
2541
- }
2542
- const dotSamaApi = this.#koniState.getSubstrateApi(chain);
2543
- const extrinsic = await getWithdrawalExtrinsic(dotSamaApi, chain, nominatorMetadata, validatorAddress);
2544
- return await this.#koniState.transactionService.handleTransaction({
2545
- address: nominatorMetadata.address,
2546
- chain: chain,
2547
- transaction: extrinsic,
2548
- data: inputData,
2549
- extrinsicType: ExtrinsicType.STAKING_WITHDRAW,
2550
- chainType: ChainType.SUBSTRATE
2551
- });
2552
- }
2553
2549
  async submitStakeClaimReward(inputData) {
2554
2550
  const {
2555
2551
  address,
2556
2552
  bondReward,
2557
- chain,
2558
- stakingType
2553
+ slug
2559
2554
  } = inputData;
2560
- if (!address) {
2555
+ const poolHandler = this.#koniState.earningService.getPoolHandler(slug);
2556
+ if (!address || !poolHandler) {
2561
2557
  return this.#koniState.transactionService.generateBeforeHandleResponseErrors([new TransactionError(BasicTxErrorType.INVALID_PARAMS)]);
2562
2558
  }
2559
+ const chain = poolHandler.chain;
2560
+ const stakingType = poolHandler.type === YieldPoolType.NOMINATION_POOL ? StakingType.POOLED : StakingType.NOMINATED;
2563
2561
  const substrateApi = this.#koniState.getSubstrateApi(chain);
2564
2562
  const extrinsic = await getClaimRewardExtrinsic(substrateApi, chain, address, stakingType, bondReward);
2565
2563
  return await this.#koniState.transactionService.handleTransaction({
@@ -2572,15 +2570,18 @@ export default class KoniExtension {
2572
2570
  });
2573
2571
  }
2574
2572
  async submitCancelStakeWithdrawal(inputData) {
2573
+ var _this$koniState$earni;
2575
2574
  const {
2576
2575
  address,
2577
- chain,
2578
- selectedUnstaking
2576
+ selectedUnstaking,
2577
+ slug
2579
2578
  } = inputData;
2579
+ const chain = (_this$koniState$earni = this.#koniState.earningService.getPoolHandler(slug)) === null || _this$koniState$earni === void 0 ? void 0 : _this$koniState$earni.chain;
2580
2580
  if (!chain || !selectedUnstaking) {
2581
2581
  return this.#koniState.transactionService.generateBeforeHandleResponseErrors([new TransactionError(BasicTxErrorType.INVALID_PARAMS)]);
2582
2582
  }
2583
2583
  const substrateApi = this.#koniState.getSubstrateApi(chain);
2584
+ // @ts-ignore
2584
2585
  const extrinsic = await getCancelWithdrawalExtrinsic(substrateApi, chain, selectedUnstaking);
2585
2586
  return await this.#koniState.transactionService.handleTransaction({
2586
2587
  address,
@@ -3553,9 +3554,237 @@ export default class KoniExtension {
3553
3554
  this.#koniState.keyringService.removeInjectAccounts(request.addresses);
3554
3555
  return true;
3555
3556
  }
3557
+ subscribeYieldPoolInfo(id, port) {
3558
+ const cb = createSubscription(id, port);
3559
+ const yieldPoolSubscription = this.#koniState.subscribeYieldPoolInfo().subscribe({
3560
+ next: rs => {
3561
+ cb(rs);
3562
+ }
3563
+ });
3564
+ this.createUnsubscriptionHandle(id, yieldPoolSubscription.unsubscribe);
3565
+ port.onDisconnect.addListener(() => {
3566
+ this.cancelSubscription(id);
3567
+ });
3568
+ return this.#koniState.getYieldPoolInfo();
3569
+ }
3570
+ async earlyValidateJoin(request) {
3571
+ return await this.#koniState.earningService.earlyValidateJoin(request);
3572
+ }
3573
+ async getOptimalYieldPath(request) {
3574
+ return await this.#koniState.earningService.generateOptimalSteps(request);
3575
+ }
3576
+ async handleYieldStep(inputData) {
3577
+ const {
3578
+ data,
3579
+ path
3580
+ } = inputData;
3581
+ const {
3582
+ address
3583
+ } = data;
3584
+ if (!data) {
3585
+ return this.#koniState.transactionService.generateBeforeHandleResponseErrors([new TransactionError(BasicTxErrorType.INTERNAL_ERROR)]);
3586
+ }
3587
+ const isLastStep = inputData.currentStep + 1 === path.steps.length;
3588
+ const yieldValidation = await this.#koniState.earningService.validateYieldJoin({
3589
+ data,
3590
+ path
3591
+ }); // TODO: validate, set to fail upon submission
3592
+
3593
+ if (yieldValidation.length > 0) {
3594
+ return this.#koniState.transactionService.generateBeforeHandleResponseErrors(yieldValidation);
3595
+ }
3596
+
3597
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
3598
+ const {
3599
+ extrinsic,
3600
+ extrinsicType,
3601
+ transferNativeAmount,
3602
+ txChain,
3603
+ txData
3604
+ } = await this.#koniState.earningService.handleYieldJoin(inputData);
3605
+ const isPoolSupportAlternativeFee = this.#koniState.earningService.isPoolSupportAlternativeFee(inputData.data.slug);
3606
+ const isMintingStep = YIELD_EXTRINSIC_TYPES.includes(extrinsicType);
3607
+ const chainInfo = this.#koniState.getChainInfo(txChain);
3608
+ return await this.#koniState.transactionService.handleTransaction({
3609
+ address,
3610
+ chain: txChain,
3611
+ transaction: extrinsic,
3612
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
3613
+ data: txData,
3614
+ extrinsicType,
3615
+ // change this depends on step
3616
+ chainType: _isChainEvmCompatible(chainInfo) ? ChainType.EVM : ChainType.SUBSTRATE,
3617
+ resolveOnDone: !isLastStep,
3618
+ transferNativeAmount,
3619
+ skipFeeValidation: isMintingStep && isPoolSupportAlternativeFee
3620
+ });
3621
+ }
3622
+ async handleYieldLeave(params) {
3623
+ const {
3624
+ address,
3625
+ slug
3626
+ } = params;
3627
+ const leaveValidation = await this.#koniState.earningService.validateYieldLeave(params);
3628
+ if (leaveValidation.length > 0) {
3629
+ return this.#koniState.transactionService.generateBeforeHandleResponseErrors(leaveValidation);
3630
+ }
3631
+ const [extrinsicType, extrinsic] = await this.#koniState.earningService.handleYieldLeave(params);
3632
+ const handler = this.#koniState.earningService.getPoolHandler(slug);
3633
+ return await this.#koniState.transactionService.handleTransaction({
3634
+ address,
3635
+ chain: (handler === null || handler === void 0 ? void 0 : handler.chain) || '',
3636
+ transaction: extrinsic,
3637
+ data: params,
3638
+ // TODO
3639
+ extrinsicType,
3640
+ chainType: (handler === null || handler === void 0 ? void 0 : handler.transactionChainType) || ChainType.SUBSTRATE
3641
+ });
3642
+ }
3643
+ async getYieldPoolTargets(request) {
3644
+ const {
3645
+ slug
3646
+ } = request;
3647
+ const targets = await this.#koniState.earningService.getPoolTargets(slug);
3648
+ return {
3649
+ slug,
3650
+ targets
3651
+ };
3652
+ }
3653
+ async subscribeYieldPosition(id, port) {
3654
+ const cb = createSubscription(id, port);
3655
+ const yieldPositionSubscription = this.#koniState.subscribeYieldPosition().subscribe({
3656
+ next: rs => {
3657
+ cb(rs);
3658
+ }
3659
+ });
3660
+ this.createUnsubscriptionHandle(id, yieldPositionSubscription.unsubscribe);
3661
+ port.onDisconnect.addListener(() => {
3662
+ this.cancelSubscription(id);
3663
+ });
3664
+ return this.#koniState.getYieldPositionInfo();
3665
+ }
3666
+ subscribeYieldReward(id, port) {
3667
+ const cb = createSubscription(id, port);
3668
+ const stakingRewardSubscription = this.#koniState.earningService.subscribeEarningReward().subscribe({
3669
+ next: rs => {
3670
+ cb(rs);
3671
+ }
3672
+ });
3673
+ this.createUnsubscriptionHandle(id, stakingRewardSubscription.unsubscribe);
3674
+ port.onDisconnect.addListener(() => {
3675
+ this.cancelSubscription(id);
3676
+ });
3677
+ return this.#koniState.earningService.getEarningRewards();
3678
+ }
3679
+ subscribeYieldRewardHistory(id, port) {
3680
+ const cb = createSubscription(id, port);
3681
+ const rewardHistorySubscription = this.#koniState.earningService.subscribeEarningRewardHistory().subscribe({
3682
+ next: rs => {
3683
+ cb(rs);
3684
+ }
3685
+ });
3686
+ this.createUnsubscriptionHandle(id, rewardHistorySubscription.unsubscribe);
3687
+ port.onDisconnect.addListener(() => {
3688
+ this.cancelSubscription(id);
3689
+ });
3690
+ return this.#koniState.earningService.getEarningRewardHistory();
3691
+ }
3692
+ subscribeEarningMinAmountPercent(id, port) {
3693
+ const cb = createSubscription(id, port);
3694
+ const earningMinAmountPercentSubscription = this.#koniState.earningService.subscribeMinAmountPercent().subscribe({
3695
+ next: rs => {
3696
+ cb(rs);
3697
+ }
3698
+ });
3699
+ this.createUnsubscriptionHandle(id, earningMinAmountPercentSubscription.unsubscribe);
3700
+ port.onDisconnect.addListener(() => {
3701
+ this.cancelSubscription(id);
3702
+ });
3703
+ return this.#koniState.earningService.getMinAmountPercent();
3704
+ }
3705
+ handleValidateYieldProcess(inputData) {
3706
+ return this.#koniState.earningService.validateYieldJoin(inputData);
3707
+ }
3708
+ async yieldSubmitWithdrawal(params) {
3709
+ const {
3710
+ address,
3711
+ slug
3712
+ } = params;
3713
+ const poolHandler = this.#koniState.earningService.getPoolHandler(slug);
3714
+ if (!poolHandler) {
3715
+ return this.#koniState.transactionService.generateBeforeHandleResponseErrors([new TransactionError(BasicTxErrorType.INVALID_PARAMS)]);
3716
+ }
3717
+ const extrinsic = await this.#koniState.earningService.handleYieldWithdraw(params);
3718
+ return await this.#koniState.transactionService.handleTransaction({
3719
+ address: address,
3720
+ chain: poolHandler.chain,
3721
+ transaction: extrinsic,
3722
+ data: params,
3723
+ extrinsicType: ExtrinsicType.STAKING_WITHDRAW,
3724
+ chainType: (poolHandler === null || poolHandler === void 0 ? void 0 : poolHandler.transactionChainType) || ChainType.SUBSTRATE
3725
+ });
3726
+ }
3727
+ async yieldSubmitCancelWithdrawal(params) {
3728
+ const {
3729
+ address,
3730
+ selectedUnstaking,
3731
+ slug
3732
+ } = params;
3733
+ const poolHandler = this.#koniState.earningService.getPoolHandler(slug);
3734
+ if (!poolHandler || !selectedUnstaking) {
3735
+ return this.#koniState.transactionService.generateBeforeHandleResponseErrors([new TransactionError(BasicTxErrorType.INVALID_PARAMS)]);
3736
+ }
3737
+ const chain = poolHandler.chain;
3738
+ const extrinsic = await this.#koniState.earningService.handleYieldCancelUnstake(params);
3739
+ return await this.#koniState.transactionService.handleTransaction({
3740
+ address,
3741
+ chain,
3742
+ transaction: extrinsic,
3743
+ data: params,
3744
+ extrinsicType: ExtrinsicType.STAKING_CANCEL_UNSTAKE,
3745
+ chainType: (poolHandler === null || poolHandler === void 0 ? void 0 : poolHandler.transactionChainType) || ChainType.SUBSTRATE
3746
+ });
3747
+ }
3748
+ async yieldSubmitClaimReward(params) {
3749
+ const {
3750
+ address,
3751
+ slug
3752
+ } = params;
3753
+ const poolHandler = this.#koniState.earningService.getPoolHandler(slug);
3754
+ if (!address || !poolHandler) {
3755
+ return this.#koniState.transactionService.generateBeforeHandleResponseErrors([new TransactionError(BasicTxErrorType.INVALID_PARAMS)]);
3756
+ }
3757
+ const extrinsic = await this.#koniState.earningService.handleYieldClaimReward(params);
3758
+ return await this.#koniState.transactionService.handleTransaction({
3759
+ address,
3760
+ chain: poolHandler.chain,
3761
+ transaction: extrinsic,
3762
+ data: params,
3763
+ extrinsicType: ExtrinsicType.STAKING_CLAIM_REWARD,
3764
+ chainType: (poolHandler === null || poolHandler === void 0 ? void 0 : poolHandler.transactionChainType) || ChainType.SUBSTRATE
3765
+ });
3766
+ }
3556
3767
 
3557
3768
  /* Campaign */
3558
3769
 
3770
+ unlockDotCheckCanMint({
3771
+ address,
3772
+ network,
3773
+ slug
3774
+ }) {
3775
+ return this.#koniState.mintCampaignService.unlockDotCampaign.canMint(address, slug, network);
3776
+ }
3777
+ unlockDotSubscribeMintedData(id, port, {
3778
+ transactionId
3779
+ }) {
3780
+ const cb = createSubscription(id, port);
3781
+ const subscription = this.#koniState.mintCampaignService.unlockDotCampaign.subscribeMintedNft(transactionId, cb);
3782
+ this.createUnsubscriptionHandle(id, subscription.unsubscribe);
3783
+ port.onDisconnect.addListener(() => {
3784
+ this.cancelSubscription(id);
3785
+ });
3786
+ return this.#koniState.mintCampaignService.unlockDotCampaign.getMintedNft(transactionId);
3787
+ }
3559
3788
  async subscribeProcessingBanner(id, port) {
3560
3789
  const cb = createSubscription(id, port);
3561
3790
  const filterBanner = data => {
@@ -3758,6 +3987,8 @@ export default class KoniExtension {
3758
3987
  return await this.subscribeBalance(id, port);
3759
3988
  case 'pri(crowdloan.getCrowdloan)':
3760
3989
  return this.getCrowdloan();
3990
+ case 'pri(crowdloan.getCrowdloanContributions)':
3991
+ return this.getCrowdloanContributions(request);
3761
3992
  case 'pri(crowdloan.getSubscription)':
3762
3993
  return this.subscribeCrowdloan(id, port);
3763
3994
  case 'pri(derivation.createV2)':
@@ -3787,6 +4018,57 @@ export default class KoniExtension {
3787
4018
  case 'pri(transaction.history.subscribe)':
3788
4019
  return this.subscribeHistoryByChainAndAddress(request, id, port);
3789
4020
 
4021
+ /* Earning */
4022
+
4023
+ /* Info */
4024
+
4025
+ case 'pri(yield.subscribePoolInfo)':
4026
+ return this.subscribeYieldPoolInfo(id, port);
4027
+ case 'pri(yield.getTargets)':
4028
+ return this.getYieldPoolTargets(request);
4029
+ case 'pri(yield.subscribeYieldPosition)':
4030
+ return this.subscribeYieldPosition(id, port);
4031
+ case 'pri(yield.subscribeYieldReward)':
4032
+ return this.subscribeYieldReward(id, port);
4033
+ case 'pri(yield.subscribeRewardHistory)':
4034
+ return this.subscribeYieldRewardHistory(id, port);
4035
+ case 'pri(yield.minAmountPercent)':
4036
+ return this.subscribeEarningMinAmountPercent(id, port);
4037
+
4038
+ /* Info */
4039
+
4040
+ /* Actions */
4041
+
4042
+ /* Join */
4043
+
4044
+ case 'pri(yield.join.earlyValidate)':
4045
+ return await this.earlyValidateJoin(request);
4046
+ case 'pri(yield.join.getOptimalPath)':
4047
+ return await this.getOptimalYieldPath(request);
4048
+ case 'pri(yield.join.handleStep)':
4049
+ return await this.handleYieldStep(request);
4050
+ case 'pri(yield.join.validateProcess)':
4051
+ return await this.handleValidateYieldProcess(request);
4052
+
4053
+ /* Join */
4054
+
4055
+ /* Others */
4056
+
4057
+ case 'pri(yield.leave.submit)':
4058
+ return await this.handleYieldLeave(request);
4059
+ case 'pri(yield.withdraw.submit)':
4060
+ return await this.yieldSubmitWithdrawal(request);
4061
+ case 'pri(yield.cancelWithdrawal.submit)':
4062
+ return await this.yieldSubmitCancelWithdrawal(request);
4063
+ case 'pri(yield.claimReward.submit)':
4064
+ return await this.yieldSubmitClaimReward(request);
4065
+
4066
+ /* Others */
4067
+
4068
+ /* Actions */
4069
+
4070
+ /* Earning */
4071
+
3790
4072
  /* Account management */
3791
4073
  // Add account
3792
4074
  case 'pri(accounts.create.suriV2)':
@@ -3905,6 +4187,8 @@ export default class KoniExtension {
3905
4187
  return this.transferGetExistentialDeposit(request);
3906
4188
  case 'pri(transfer.getMaxTransferable)':
3907
4189
  return this.transferGetMaxTransferable(request);
4190
+ case 'pri(transfer.subscribeMaxTransferable)':
4191
+ return this.transferGetMaxTransferable(request);
3908
4192
  case 'pri(freeBalance.get)':
3909
4193
  return this.getAddressFreeBalance(request);
3910
4194
  case 'pri(freeBalance.subscribe)':
@@ -3963,8 +4247,6 @@ export default class KoniExtension {
3963
4247
  return await this.submitBonding(request);
3964
4248
  case 'pri(unbonding.submitTransaction)':
3965
4249
  return await this.submitUnbonding(request);
3966
- case 'pri(unbonding.submitWithdrawal)':
3967
- return await this.submitStakeWithdrawal(request);
3968
4250
  case 'pri(staking.submitClaimReward)':
3969
4251
  return await this.submitStakeClaimReward(request);
3970
4252
  case 'pri(staking.submitCancelWithdrawal)':
@@ -4068,6 +4350,15 @@ export default class KoniExtension {
4068
4350
  case 'pri(mantaPay.subscribeSyncingState)':
4069
4351
  return this.subscribeMantaPaySyncState(id, port);
4070
4352
 
4353
+ /* Campaign */
4354
+
4355
+ case 'pri(campaign.unlockDot.canMint)':
4356
+ return this.unlockDotCheckCanMint(request);
4357
+ case 'pri(campaign.unlockDot.subscribe)':
4358
+ return this.unlockDotSubscribeMintedData(id, port, request);
4359
+
4360
+ /* Campaign */
4361
+
4071
4362
  // Metadata
4072
4363
  case 'pri(metadata.find)':
4073
4364
  return this.findRawMetadata(request);
@@ -1,16 +1,18 @@
1
1
  /// <reference types="chrome" />
2
2
  import { _AssetRef, _AssetType, _ChainAsset, _ChainInfo, _MultiChainAsset } from '@subwallet/chain-list/types';
3
- import { AddTokenRequestExternal, AmountData, ApiMap, AuthRequestV2, ChainStakingMetadata, ConfirmationsQueue, CrowdloanItem, CrowdloanJson, CurrentAccountInfo, EvmSendTransactionParams, ExternalRequestPromise, MantaPayConfig, MantaPaySyncState, NftCollection, NftItem, NftJson, NominatorMetadata, RequestAccountExportPrivateKey, RequestCheckPublicAndSecretKey, RequestConfirmationComplete, RequestSettingsType, ResponseAccountExportPrivateKey, ResponseCheckPublicAndSecretKey, ServiceInfo, SingleModeJson, StakingItem, StakingJson, StakingRewardItem, StakingRewardJson, StakingType, UiSettings } from '@subwallet/extension-base/background/KoniTypes';
3
+ import { AddTokenRequestExternal, AmountData, ApiMap, AuthRequestV2, ChainStakingMetadata, ConfirmationsQueue, CrowdloanItem, CrowdloanJson, CurrentAccountInfo, EvmSendTransactionParams, ExternalRequestPromise, MantaPayConfig, MantaPaySyncState, NftCollection, NftItem, NftJson, NominatorMetadata, RequestAccountExportPrivateKey, RequestCheckPublicAndSecretKey, RequestConfirmationComplete, RequestCrowdloanContributions, RequestSettingsType, ResponseAccountExportPrivateKey, ResponseCheckPublicAndSecretKey, ServiceInfo, SingleModeJson, StakingItem, StakingJson, StakingRewardItem, StakingRewardJson, StakingType, UiSettings } from '@subwallet/extension-base/background/KoniTypes';
4
4
  import { AccountJson, RequestAuthorizeTab, RequestRpcSend, RequestRpcSubscribe, RequestRpcUnsubscribe, RequestSign, ResponseRpcListProviders, ResponseSigning } from '@subwallet/extension-base/background/types';
5
5
  import { BalanceService } from '@subwallet/extension-base/services/balance-service';
6
6
  import BuyService from '@subwallet/extension-base/services/buy-service';
7
7
  import CampaignService from '@subwallet/extension-base/services/campaign-service';
8
8
  import { ChainService } from '@subwallet/extension-base/services/chain-service';
9
9
  import { _ChainState, _NetworkUpsertParams, _ValidateCustomAssetRequest } from '@subwallet/extension-base/services/chain-service/types';
10
+ import EarningService from '@subwallet/extension-base/services/earning-service/service';
10
11
  import { EventService } from '@subwallet/extension-base/services/event-service';
11
12
  import { HistoryService } from '@subwallet/extension-base/services/history-service';
12
13
  import { KeyringService } from '@subwallet/extension-base/services/keyring-service';
13
14
  import MigrationService from '@subwallet/extension-base/services/migration-service';
15
+ import MintCampaignService from '@subwallet/extension-base/services/mint-campaign-service';
14
16
  import NotificationService from '@subwallet/extension-base/services/notification-service/NotificationService';
15
17
  import { PriceService } from '@subwallet/extension-base/services/price-service';
16
18
  import RequestService from '@subwallet/extension-base/services/request-service';
@@ -20,7 +22,7 @@ import DatabaseService from '@subwallet/extension-base/services/storage-service/
20
22
  import { SubscanService } from '@subwallet/extension-base/services/subscan-service';
21
23
  import TransactionService from '@subwallet/extension-base/services/transaction-service';
22
24
  import WalletConnectService from '@subwallet/extension-base/services/wallet-connect-service';
23
- import { BalanceItem, BalanceJson, BalanceMap } from '@subwallet/extension-base/types';
25
+ import { BalanceItem, BalanceJson, BalanceMap, YieldPoolInfo, YieldPoolType, YieldPositionInfo } from '@subwallet/extension-base/types';
24
26
  import { MetadataDef, ProviderMeta } from '@subwallet/extension-inject/types';
25
27
  import SimpleKeyring from 'eth-simple-keyring';
26
28
  import { BehaviorSubject, Subject } from 'rxjs';
@@ -46,6 +48,8 @@ export default class KoniState {
46
48
  private stakingNominatorMetadataSubject;
47
49
  private stakingRewardSubject;
48
50
  private stakingRewardState;
51
+ private yieldPoolInfoSubject;
52
+ private yieldPositionSubject;
49
53
  private lazyMap;
50
54
  readonly notificationService: NotificationService;
51
55
  readonly eventService: EventService;
@@ -64,8 +68,10 @@ export default class KoniState {
64
68
  readonly migrationService: MigrationService;
65
69
  readonly subscanService: SubscanService;
66
70
  readonly walletConnectService: WalletConnectService;
71
+ readonly mintCampaignService: MintCampaignService;
67
72
  readonly campaignService: CampaignService;
68
73
  readonly buyService: BuyService;
74
+ readonly earningService: EarningService;
69
75
  private generalStatus;
70
76
  private waitSleeping;
71
77
  private waitStarting;
@@ -108,6 +114,11 @@ export default class KoniState {
108
114
  getStaking(): Promise<StakingJson>;
109
115
  getStakingOwnersByChains(chains: string[]): Promise<string[]>;
110
116
  getPooledStakingRecordsByAddress(addresses: string[]): Promise<StakingItem[]>;
117
+ getPooledPositionByAddress(addresses: string[]): Promise<YieldPositionInfo[]>;
118
+ subscribeYieldPoolInfo(): Subject<YieldPoolInfo[]>;
119
+ subscribeYieldPosition(): Subject<YieldPositionInfo[]>;
120
+ getYieldPoolInfo(): Promise<YieldPoolInfo[]>;
121
+ getYieldPositionInfo(): Promise<YieldPositionInfo[]>;
111
122
  subscribeMantaPayConfig(): Subject<MantaPayConfig[]>;
112
123
  subscribeStaking(): Subject<StakingJson>;
113
124
  subscribeChainStakingMetadata(): Subject<ChainStakingMetadata[]>;
@@ -251,5 +262,10 @@ export default class KoniState {
251
262
  metadata: string;
252
263
  specVersion: number;
253
264
  }>;
265
+ updateYieldPoolInfo(data: YieldPoolInfo): void;
266
+ resetYieldPoolInfo(chains: string[]): void;
267
+ updateYieldPosition(data: YieldPositionInfo): void;
268
+ getYieldPoolStakingInfo(chain: string, poolType: YieldPoolType): Promise<YieldPoolInfo | undefined>;
269
+ getCrowdloanContributions({ address, page, relayChain }: RequestCrowdloanContributions): Promise<import("../../../services/subscan-service/types").CrowdloanContributionsResponse>;
254
270
  }
255
271
  export {};
@@ -14,10 +14,12 @@ import CampaignService from '@subwallet/extension-base/services/campaign-service
14
14
  import { ChainService } from '@subwallet/extension-base/services/chain-service';
15
15
  import { _DEFAULT_MANTA_ZK_CHAIN, _MANTA_ZK_CHAIN_GROUP, _PREDEFINED_SINGLE_MODES } from '@subwallet/extension-base/services/chain-service/constants';
16
16
  import { _getEvmChainId, _getSubstrateGenesisHash, _getTokenOnChainAssetId, _isAssetFungibleToken, _isChainEnabled, _isChainTestNet, _parseMetadataForSmartContractAsset } from '@subwallet/extension-base/services/chain-service/utils';
17
+ import EarningService from '@subwallet/extension-base/services/earning-service/service';
17
18
  import { EventService } from '@subwallet/extension-base/services/event-service';
18
19
  import { HistoryService } from '@subwallet/extension-base/services/history-service';
19
20
  import { KeyringService } from '@subwallet/extension-base/services/keyring-service';
20
21
  import MigrationService from '@subwallet/extension-base/services/migration-service';
22
+ import MintCampaignService from '@subwallet/extension-base/services/mint-campaign-service';
21
23
  import NotificationService from '@subwallet/extension-base/services/notification-service/NotificationService';
22
24
  import { PriceService } from '@subwallet/extension-base/services/price-service';
23
25
  import RequestService from '@subwallet/extension-base/services/request-service';
@@ -75,6 +77,10 @@ export default class KoniState {
75
77
  ready: false,
76
78
  data: {}
77
79
  };
80
+
81
+ // earning
82
+ yieldPoolInfoSubject = new Subject();
83
+ yieldPositionSubject = new Subject();
78
84
  lazyMap = {};
79
85
  // Handle the general status of the extension
80
86
  generalStatus = ServiceStatus.INITIALIZING;
@@ -93,11 +99,13 @@ export default class KoniState {
93
99
  this.priceService = new PriceService(this.dbService, this.eventService, this.chainService);
94
100
  this.balanceService = new BalanceService(this);
95
101
  this.historyService = new HistoryService(this.dbService, this.chainService, this.eventService, this.keyringService, this.subscanService);
96
- this.transactionService = new TransactionService(this.chainService, this.eventService, this.requestService, this.balanceService, this.historyService, this.notificationService, this.dbService);
102
+ this.mintCampaignService = new MintCampaignService(this);
97
103
  this.walletConnectService = new WalletConnectService(this, this.requestService);
98
104
  this.migrationService = new MigrationService(this, this.eventService);
99
105
  this.campaignService = new CampaignService(this);
100
106
  this.buyService = new BuyService(this);
107
+ this.transactionService = new TransactionService(this);
108
+ this.earningService = new EarningService(this);
101
109
  this.subscription = new KoniSubscription(this, this.dbService);
102
110
  this.cron = new KoniCron(this, this.subscription, this.dbService);
103
111
  this.logger = createLogger('State');
@@ -240,6 +248,7 @@ export default class KoniState {
240
248
  }
241
249
  async startSubscription() {
242
250
  await this.eventService.waitKeyringReady;
251
+ await this.eventService.waitAssetReady;
243
252
  this.dbService.subscribeChainStakingMetadata([], data => {
244
253
  this.chainStakingMetadataSubject.next(data);
245
254
  });
@@ -250,8 +259,8 @@ export default class KoniState {
250
259
  this.keyringService.accountSubject.subscribe(accounts => {
251
260
  // TODO: improve this
252
261
  unsub && unsub.unsubscribe();
253
- unsub = this.dbService.subscribeNominatorMetadata(Object.keys(accounts), data => {
254
- this.stakingNominatorMetadataSubject.next(data);
262
+ unsub = this.dbService.subscribeYieldPosition(Object.keys(accounts), data => {
263
+ this.yieldPositionSubject.next(data);
255
264
  });
256
265
  });
257
266
  }
@@ -343,6 +352,22 @@ export default class KoniState {
343
352
  async getPooledStakingRecordsByAddress(addresses) {
344
353
  return this.dbService.getPooledStakings(addresses, this.activeChainSlugs);
345
354
  }
355
+ async getPooledPositionByAddress(addresses) {
356
+ return this.dbService.getYieldNominationPoolPosition(addresses, this.activeChainSlugs);
357
+ }
358
+ subscribeYieldPoolInfo() {
359
+ return this.yieldPoolInfoSubject;
360
+ }
361
+ subscribeYieldPosition() {
362
+ return this.yieldPositionSubject;
363
+ }
364
+ getYieldPoolInfo() {
365
+ return this.dbService.getYieldPools();
366
+ }
367
+ getYieldPositionInfo() {
368
+ const addresses = this.getDecodedAddresses(this.keyringService.currentAccount.address);
369
+ return this.dbService.getYieldPositionByAddress(addresses);
370
+ }
346
371
  subscribeMantaPayConfig() {
347
372
  return this.mantaPayConfigSubject;
348
373
  }
@@ -1741,4 +1766,26 @@ export default class KoniState {
1741
1766
  specVersion: parseInt((metadata === null || metadata === void 0 ? void 0 : metadata.specVersion) || '0')
1742
1767
  };
1743
1768
  }
1769
+ updateYieldPoolInfo(data) {
1770
+ this.dbService.updateYieldPoolStore(data).catch(e => this.logger.warn(e));
1771
+ }
1772
+ resetYieldPoolInfo(chains) {
1773
+ this.dbService.subscribeYieldPoolInfo(chains, data => {
1774
+ // TODO: no unsub
1775
+ this.yieldPoolInfoSubject.next(data);
1776
+ });
1777
+ }
1778
+ updateYieldPosition(data) {
1779
+ this.dbService.updateYieldPosition(data).catch(e => this.logger.warn(e));
1780
+ }
1781
+ getYieldPoolStakingInfo(chain, poolType) {
1782
+ return this.dbService.getYieldPoolStakingInfo(chain, poolType);
1783
+ }
1784
+ getCrowdloanContributions({
1785
+ address,
1786
+ page,
1787
+ relayChain
1788
+ }) {
1789
+ return this.subscanService.getCrowdloanContributions(relayChain, address, page);
1790
+ }
1744
1791
  }
@@ -58,7 +58,8 @@ export default function handlers({
58
58
  assert(port, 'Port has been disconnected');
59
59
  port.postMessage({
60
60
  id,
61
- response
61
+ response,
62
+ sender: 'BACKGROUND'
62
63
  });
63
64
  }).catch(error => {
64
65
  console.error(error);
@@ -70,7 +71,8 @@ export default function handlers({
70
71
  error: error.message,
71
72
  errorCode: error.code,
72
73
  errorData: error.data,
73
- id
74
+ id,
75
+ sender: 'BACKGROUND'
74
76
  });
75
77
  }
76
78
  });