@subwallet/extension-base 1.1.31-beta.0 → 1.1.33-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 (319) hide show
  1. package/background/KoniTypes.d.ts +71 -111
  2. package/background/KoniTypes.js +14 -19
  3. package/background/errors/TransactionError.js +0 -9
  4. package/cjs/background/KoniTypes.js +17 -20
  5. package/cjs/background/errors/TransactionError.js +0 -9
  6. package/cjs/constants/index.js +4 -19
  7. package/cjs/koni/api/nft/config.js +23 -33
  8. package/cjs/koni/api/nft/index.js +0 -14
  9. package/cjs/koni/api/nft/nft.js +22 -1
  10. package/cjs/koni/api/staking/bonding/amplitude.js +108 -76
  11. package/cjs/koni/api/staking/bonding/astar.js +10 -11
  12. package/cjs/koni/api/staking/bonding/index.js +3 -4
  13. package/cjs/koni/api/staking/bonding/paraChain.js +29 -28
  14. package/cjs/koni/api/staking/bonding/relayChain.js +45 -48
  15. package/cjs/koni/api/staking/bonding/utils.js +86 -104
  16. package/cjs/koni/api/staking/index.js +5 -6
  17. package/cjs/koni/api/staking/paraChain.js +36 -11
  18. package/cjs/koni/api/staking/relayChain.js +2 -3
  19. package/cjs/koni/api/xcm/xTokens.js +1 -1
  20. package/cjs/koni/background/cron.js +1 -11
  21. package/cjs/koni/background/handlers/Extension.js +69 -362
  22. package/cjs/koni/background/handlers/State.js +3 -51
  23. package/cjs/koni/background/handlers/Tabs.js +19 -2
  24. package/cjs/koni/background/handlers/index.js +2 -4
  25. package/cjs/koni/background/subscription.js +37 -95
  26. package/cjs/packageInfo.js +1 -1
  27. package/cjs/services/campaign-service/index.js +25 -9
  28. package/cjs/services/chain-service/constants.js +21 -4
  29. package/cjs/services/chain-service/index.js +2 -3
  30. package/cjs/services/chain-service/utils.js +1 -7
  31. package/cjs/services/event-service/index.js +0 -4
  32. package/cjs/services/history-service/index.js +12 -8
  33. package/cjs/services/keyring-service/index.js +2 -14
  34. package/cjs/services/migration-service/scripts/MigrateLedgerAccount.js +1 -1
  35. package/cjs/services/migration-service/scripts/MigrateTransactionHistory.js +1 -1
  36. package/cjs/services/migration-service/scripts/index.js +1 -7
  37. package/cjs/services/notification-service/NotificationService.js +1 -1
  38. package/cjs/services/storage-service/DatabaseService.js +3 -51
  39. package/cjs/services/storage-service/databases/index.js +0 -4
  40. package/cjs/services/storage-service/db-stores/Campaign.js +9 -3
  41. package/cjs/services/storage-service/db-stores/NominatorMetadata.js +3 -3
  42. package/cjs/services/subscan-service/index.js +0 -16
  43. package/cjs/services/transaction-service/event-parser/index.js +0 -58
  44. package/cjs/services/transaction-service/helpers/index.js +1 -3
  45. package/cjs/services/transaction-service/index.js +131 -242
  46. package/cjs/services/transaction-service/utils.js +0 -1
  47. package/cjs/types/index.js +0 -44
  48. package/cjs/utils/fetchEvmChainInfo.js +20 -0
  49. package/cjs/utils/fetchStaticData.js +1 -2
  50. package/cjs/utils/index.js +17 -81
  51. package/cjs/utils/number.js +1 -3
  52. package/constants/index.d.ts +1 -6
  53. package/constants/index.js +1 -6
  54. package/koni/api/nft/config.js +23 -33
  55. package/koni/api/nft/index.js +1 -15
  56. package/koni/api/nft/nft.js +23 -2
  57. package/koni/api/staking/bonding/amplitude.d.ts +1 -1
  58. package/koni/api/staking/bonding/amplitude.js +105 -73
  59. package/koni/api/staking/bonding/astar.js +8 -9
  60. package/koni/api/staking/bonding/index.d.ts +2 -1
  61. package/koni/api/staking/bonding/index.js +3 -5
  62. package/koni/api/staking/bonding/paraChain.js +16 -15
  63. package/koni/api/staking/bonding/relayChain.d.ts +2 -2
  64. package/koni/api/staking/bonding/relayChain.js +30 -33
  65. package/koni/api/staking/bonding/utils.d.ts +42 -15
  66. package/koni/api/staking/bonding/utils.js +69 -85
  67. package/koni/api/staking/index.js +1 -2
  68. package/koni/api/staking/paraChain.js +37 -12
  69. package/koni/api/staking/relayChain.js +3 -4
  70. package/koni/api/xcm/xTokens.js +1 -1
  71. package/koni/background/cron.d.ts +0 -1
  72. package/koni/background/cron.js +2 -12
  73. package/koni/background/handlers/Extension.d.ts +1 -17
  74. package/koni/background/handlers/Extension.js +30 -321
  75. package/koni/background/handlers/State.d.ts +2 -18
  76. package/koni/background/handlers/State.js +3 -50
  77. package/koni/background/handlers/Tabs.js +20 -3
  78. package/koni/background/handlers/index.js +2 -4
  79. package/koni/background/subscription.d.ts +1 -6
  80. package/koni/background/subscription.js +38 -97
  81. package/package.json +13 -321
  82. package/packageInfo.js +1 -1
  83. package/services/campaign-service/index.js +25 -9
  84. package/services/chain-service/constants.d.ts +12 -0
  85. package/services/chain-service/constants.js +19 -3
  86. package/services/chain-service/index.js +2 -3
  87. package/services/chain-service/utils.d.ts +0 -1
  88. package/services/chain-service/utils.js +1 -5
  89. package/services/event-service/index.d.ts +0 -1
  90. package/services/event-service/index.js +0 -4
  91. package/services/event-service/types.d.ts +1 -8
  92. package/services/history-service/index.js +12 -8
  93. package/services/keyring-service/index.d.ts +1 -2
  94. package/services/keyring-service/index.js +2 -14
  95. package/services/migration-service/scripts/MigrateLedgerAccount.js +1 -1
  96. package/services/migration-service/scripts/MigrateTransactionHistory.js +1 -1
  97. package/services/migration-service/scripts/index.js +1 -7
  98. package/services/notification-service/NotificationService.js +1 -1
  99. package/services/storage-service/DatabaseService.d.ts +2 -18
  100. package/services/storage-service/DatabaseService.js +3 -51
  101. package/services/storage-service/databases/index.d.ts +1 -3
  102. package/services/storage-service/databases/index.js +0 -4
  103. package/services/storage-service/db-stores/Campaign.js +9 -3
  104. package/services/storage-service/db-stores/NominatorMetadata.js +3 -3
  105. package/services/subscan-service/index.d.ts +2 -3
  106. package/services/subscan-service/index.js +0 -15
  107. package/services/subscan-service/types.d.ts +0 -20
  108. package/services/transaction-service/event-parser/index.d.ts +1 -3
  109. package/services/transaction-service/event-parser/index.js +1 -57
  110. package/services/transaction-service/helpers/index.js +1 -3
  111. package/services/transaction-service/index.d.ts +16 -4
  112. package/services/transaction-service/index.js +118 -230
  113. package/services/transaction-service/types.d.ts +1 -2
  114. package/services/transaction-service/utils.js +0 -1
  115. package/types/index.d.ts +0 -5
  116. package/types/index.js +1 -5
  117. package/utils/fetchEvmChainInfo.d.ts +17 -0
  118. package/utils/fetchEvmChainInfo.js +14 -0
  119. package/utils/fetchStaticData.js +1 -2
  120. package/utils/index.d.ts +2 -5
  121. package/utils/index.js +2 -52
  122. package/utils/number.d.ts +1 -1
  123. package/utils/number.js +1 -1
  124. package/cjs/koni/api/dotsama/balance.js +0 -464
  125. package/cjs/koni/api/nft/ordinal_nft/constants.js +0 -21
  126. package/cjs/koni/api/nft/ordinal_nft/index.js +0 -121
  127. package/cjs/koni/api/nft/ordinal_nft/utils.js +0 -41
  128. package/cjs/koni/api/yield/helper/utils.js +0 -46
  129. package/cjs/services/earning-service/constants/chains.js +0 -29
  130. package/cjs/services/earning-service/constants/index.js +0 -27
  131. package/cjs/services/earning-service/constants/step.js +0 -18
  132. package/cjs/services/earning-service/handlers/base.js +0 -259
  133. package/cjs/services/earning-service/handlers/index.js +0 -60
  134. package/cjs/services/earning-service/handlers/lending/base.js +0 -20
  135. package/cjs/services/earning-service/handlers/lending/index.js +0 -13
  136. package/cjs/services/earning-service/handlers/lending/interlay.js +0 -191
  137. package/cjs/services/earning-service/handlers/liquid-staking/acala.js +0 -239
  138. package/cjs/services/earning-service/handlers/liquid-staking/base.js +0 -43
  139. package/cjs/services/earning-service/handlers/liquid-staking/bifrost.js +0 -297
  140. package/cjs/services/earning-service/handlers/liquid-staking/index.js +0 -34
  141. package/cjs/services/earning-service/handlers/liquid-staking/parallel.js +0 -226
  142. package/cjs/services/earning-service/handlers/liquid-staking/stella-swap.js +0 -395
  143. package/cjs/services/earning-service/handlers/native-staking/amplitude.js +0 -384
  144. package/cjs/services/earning-service/handlers/native-staking/astar.js +0 -461
  145. package/cjs/services/earning-service/handlers/native-staking/base-para.js +0 -146
  146. package/cjs/services/earning-service/handlers/native-staking/base.js +0 -159
  147. package/cjs/services/earning-service/handlers/native-staking/index.js +0 -34
  148. package/cjs/services/earning-service/handlers/native-staking/para-chain.js +0 -385
  149. package/cjs/services/earning-service/handlers/native-staking/relay-chain.js +0 -558
  150. package/cjs/services/earning-service/handlers/nomination-pool/index.js +0 -560
  151. package/cjs/services/earning-service/handlers/special.js +0 -503
  152. package/cjs/services/earning-service/service.js +0 -387
  153. package/cjs/services/earning-service/utils/index.js +0 -128
  154. package/cjs/services/migration-service/scripts/DeleteEarningData.js +0 -21
  155. package/cjs/services/migration-service/scripts/EnableEarningChains.js +0 -21
  156. package/cjs/services/migration-service/scripts/MigrateEthProvider.js +0 -17
  157. package/cjs/services/migration-service/scripts/MigratePioneerProvider.js +0 -17
  158. package/cjs/services/migration-service/scripts/MigrateProvider.js +0 -29
  159. package/cjs/services/migration-service/scripts/databases/MigrateEarningHistory.js +0 -21
  160. package/cjs/services/migration-service/scripts/databases/MigrateEarningVersion.js +0 -21
  161. package/cjs/services/mint-campaign-service/campaigns/UnlockDotCampaign.js +0 -149
  162. package/cjs/services/mint-campaign-service/campaigns/index.js +0 -13
  163. package/cjs/services/mint-campaign-service/constants.js +0 -11
  164. package/cjs/services/mint-campaign-service/index.js +0 -18
  165. package/cjs/services/storage-service/db-stores/YieldPoolStore.js +0 -36
  166. package/cjs/services/storage-service/db-stores/YieldPositionStore.js +0 -65
  167. package/cjs/services/storage-service/index.js +0 -241
  168. package/cjs/types/campaigns/index.js +0 -16
  169. package/cjs/types/campaigns/unlock-dot.js +0 -1
  170. package/cjs/types/ordinal.js +0 -1
  171. package/cjs/types/transaction.js +0 -1
  172. package/cjs/types/yield/actions/index.js +0 -27
  173. package/cjs/types/yield/actions/join/index.js +0 -38
  174. package/cjs/types/yield/actions/join/step.js +0 -47
  175. package/cjs/types/yield/actions/join/submit.js +0 -1
  176. package/cjs/types/yield/actions/join/validate.js +0 -16
  177. package/cjs/types/yield/actions/others.js +0 -1
  178. package/cjs/types/yield/index.js +0 -27
  179. package/cjs/types/yield/info/account/index.js +0 -49
  180. package/cjs/types/yield/info/account/info.js +0 -1
  181. package/cjs/types/yield/info/account/reward.js +0 -1
  182. package/cjs/types/yield/info/account/target.js +0 -32
  183. package/cjs/types/yield/info/account/unstake.js +0 -27
  184. package/cjs/types/yield/info/base.js +0 -41
  185. package/cjs/types/yield/info/chain/index.js +0 -27
  186. package/cjs/types/yield/info/chain/info.js +0 -1
  187. package/cjs/types/yield/info/chain/target.js +0 -1
  188. package/cjs/types/yield/info/index.js +0 -49
  189. package/cjs/types/yield/info/pallet.js +0 -15
  190. package/cjs/types.js +0 -1
  191. package/cjs/utils/address.js +0 -34
  192. package/cjs/utils/keyring.js +0 -57
  193. package/cjs/utils/object.js +0 -12
  194. package/koni/api/nft/ordinal_nft/constants.d.ts +0 -9
  195. package/koni/api/nft/ordinal_nft/constants.js +0 -12
  196. package/koni/api/nft/ordinal_nft/index.d.ts +0 -8
  197. package/koni/api/nft/ordinal_nft/index.js +0 -114
  198. package/koni/api/nft/ordinal_nft/utils.d.ts +0 -2
  199. package/koni/api/nft/ordinal_nft/utils.js +0 -33
  200. package/koni/api/yield/helper/utils.d.ts +0 -10
  201. package/koni/api/yield/helper/utils.js +0 -32
  202. package/services/earning-service/constants/abis/compound_finance_v2_abi.json +0 -1235
  203. package/services/earning-service/constants/abis/st_liquid_token_abi.json +0 -1355
  204. package/services/earning-service/constants/chains.d.ts +0 -14
  205. package/services/earning-service/constants/chains.js +0 -21
  206. package/services/earning-service/constants/index.d.ts +0 -2
  207. package/services/earning-service/constants/index.js +0 -5
  208. package/services/earning-service/constants/step.d.ts +0 -3
  209. package/services/earning-service/constants/step.js +0 -10
  210. package/services/earning-service/handlers/base.d.ts +0 -112
  211. package/services/earning-service/handlers/base.js +0 -253
  212. package/services/earning-service/handlers/index.d.ts +0 -5
  213. package/services/earning-service/handlers/index.js +0 -8
  214. package/services/earning-service/handlers/lending/base.d.ts +0 -6
  215. package/services/earning-service/handlers/lending/base.js +0 -12
  216. package/services/earning-service/handlers/lending/index.d.ts +0 -1
  217. package/services/earning-service/handlers/lending/index.js +0 -4
  218. package/services/earning-service/handlers/lending/interlay.d.ts +0 -24
  219. package/services/earning-service/handlers/lending/interlay.js +0 -183
  220. package/services/earning-service/handlers/liquid-staking/acala.d.ts +0 -27
  221. package/services/earning-service/handlers/liquid-staking/acala.js +0 -231
  222. package/services/earning-service/handlers/liquid-staking/base.d.ts +0 -9
  223. package/services/earning-service/handlers/liquid-staking/base.js +0 -35
  224. package/services/earning-service/handlers/liquid-staking/bifrost.d.ts +0 -46
  225. package/services/earning-service/handlers/liquid-staking/bifrost.js +0 -286
  226. package/services/earning-service/handlers/liquid-staking/index.d.ts +0 -4
  227. package/services/earning-service/handlers/liquid-staking/index.js +0 -7
  228. package/services/earning-service/handlers/liquid-staking/parallel.d.ts +0 -26
  229. package/services/earning-service/handlers/liquid-staking/parallel.js +0 -218
  230. package/services/earning-service/handlers/liquid-staking/stella-swap.d.ts +0 -34
  231. package/services/earning-service/handlers/liquid-staking/stella-swap.js +0 -385
  232. package/services/earning-service/handlers/native-staking/amplitude.d.ts +0 -22
  233. package/services/earning-service/handlers/native-staking/amplitude.js +0 -375
  234. package/services/earning-service/handlers/native-staking/astar.d.ts +0 -19
  235. package/services/earning-service/handlers/native-staking/astar.js +0 -451
  236. package/services/earning-service/handlers/native-staking/base-para.d.ts +0 -11
  237. package/services/earning-service/handlers/native-staking/base-para.js +0 -138
  238. package/services/earning-service/handlers/native-staking/base.d.ts +0 -21
  239. package/services/earning-service/handlers/native-staking/base.js +0 -150
  240. package/services/earning-service/handlers/native-staking/index.d.ts +0 -4
  241. package/services/earning-service/handlers/native-staking/index.js +0 -7
  242. package/services/earning-service/handlers/native-staking/para-chain.d.ts +0 -15
  243. package/services/earning-service/handlers/native-staking/para-chain.js +0 -377
  244. package/services/earning-service/handlers/native-staking/relay-chain.d.ts +0 -21
  245. package/services/earning-service/handlers/native-staking/relay-chain.js +0 -549
  246. package/services/earning-service/handlers/nomination-pool/index.d.ts +0 -36
  247. package/services/earning-service/handlers/nomination-pool/index.js +0 -550
  248. package/services/earning-service/handlers/special.d.ts +0 -65
  249. package/services/earning-service/handlers/special.js +0 -495
  250. package/services/earning-service/service.d.ts +0 -45
  251. package/services/earning-service/service.js +0 -379
  252. package/services/earning-service/utils/index.d.ts +0 -18
  253. package/services/earning-service/utils/index.js +0 -112
  254. package/services/migration-service/scripts/DeleteEarningData.d.ts +0 -4
  255. package/services/migration-service/scripts/DeleteEarningData.js +0 -13
  256. package/services/migration-service/scripts/EnableEarningChains.d.ts +0 -4
  257. package/services/migration-service/scripts/EnableEarningChains.js +0 -13
  258. package/services/migration-service/scripts/databases/MigrateEarningHistory.d.ts +0 -4
  259. package/services/migration-service/scripts/databases/MigrateEarningHistory.js +0 -13
  260. package/services/migration-service/scripts/databases/MigrateEarningVersion.d.ts +0 -4
  261. package/services/migration-service/scripts/databases/MigrateEarningVersion.js +0 -13
  262. package/services/mint-campaign-service/campaigns/UnlockDotCampaign.d.ts +0 -13
  263. package/services/mint-campaign-service/campaigns/UnlockDotCampaign.js +0 -139
  264. package/services/mint-campaign-service/campaigns/index.d.ts +0 -1
  265. package/services/mint-campaign-service/campaigns/index.js +0 -4
  266. package/services/mint-campaign-service/constants.d.ts +0 -1
  267. package/services/mint-campaign-service/constants.js +0 -4
  268. package/services/mint-campaign-service/index.d.ts +0 -7
  269. package/services/mint-campaign-service/index.js +0 -11
  270. package/services/storage-service/db-stores/YieldPoolStore.d.ts +0 -10
  271. package/services/storage-service/db-stores/YieldPoolStore.js +0 -28
  272. package/services/storage-service/db-stores/YieldPositionStore.d.ts +0 -9
  273. package/services/storage-service/db-stores/YieldPositionStore.js +0 -57
  274. package/types/campaigns/index.d.ts +0 -1
  275. package/types/campaigns/index.js +0 -4
  276. package/types/campaigns/unlock-dot.d.ts +0 -71
  277. package/types/campaigns/unlock-dot.js +0 -1
  278. package/types/ordinal.d.ts +0 -69
  279. package/types/ordinal.js +0 -1
  280. package/types/transaction.d.ts +0 -3
  281. package/types/transaction.js +0 -1
  282. package/types/yield/actions/index.d.ts +0 -2
  283. package/types/yield/actions/index.js +0 -5
  284. package/types/yield/actions/join/index.d.ts +0 -3
  285. package/types/yield/actions/join/index.js +0 -6
  286. package/types/yield/actions/join/step.d.ts +0 -95
  287. package/types/yield/actions/join/step.js +0 -46
  288. package/types/yield/actions/join/submit.d.ts +0 -57
  289. package/types/yield/actions/join/submit.js +0 -1
  290. package/types/yield/actions/join/validate.d.ts +0 -18
  291. package/types/yield/actions/join/validate.js +0 -10
  292. package/types/yield/actions/others.d.ts +0 -85
  293. package/types/yield/actions/others.js +0 -1
  294. package/types/yield/index.d.ts +0 -2
  295. package/types/yield/index.js +0 -5
  296. package/types/yield/info/account/index.d.ts +0 -4
  297. package/types/yield/info/account/index.js +0 -7
  298. package/types/yield/info/account/info.d.ts +0 -92
  299. package/types/yield/info/account/info.js +0 -1
  300. package/types/yield/info/account/reward.d.ts +0 -45
  301. package/types/yield/info/account/reward.js +0 -1
  302. package/types/yield/info/account/target.d.ts +0 -43
  303. package/types/yield/info/account/target.js +0 -27
  304. package/types/yield/info/account/unstake.d.ts +0 -31
  305. package/types/yield/info/account/unstake.js +0 -22
  306. package/types/yield/info/base.d.ts +0 -45
  307. package/types/yield/info/base.js +0 -36
  308. package/types/yield/info/chain/index.d.ts +0 -2
  309. package/types/yield/info/chain/index.js +0 -5
  310. package/types/yield/info/chain/info.d.ts +0 -251
  311. package/types/yield/info/chain/info.js +0 -1
  312. package/types/yield/info/chain/target.d.ts +0 -37
  313. package/types/yield/info/chain/target.js +0 -1
  314. package/types/yield/info/index.d.ts +0 -4
  315. package/types/yield/info/index.js +0 -7
  316. package/types/yield/info/pallet.d.ts +0 -143
  317. package/types/yield/info/pallet.js +0 -9
  318. package/utils/object.d.ts +0 -1
  319. package/utils/object.js +0 -6
@@ -1,495 +0,0 @@
1
- // Copyright 2019-2022 @subwallet/extension-base
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- import { COMMON_CHAIN_SLUGS } from '@subwallet/chain-list';
5
- import { TransactionError } from '@subwallet/extension-base/background/errors/TransactionError';
6
- import { BasicTxErrorType, ExtrinsicType, StakingTxErrorType } from '@subwallet/extension-base/background/KoniTypes';
7
- import { ALL_ACCOUNT_KEY } from '@subwallet/extension-base/constants';
8
- import { createXcmExtrinsic } from '@subwallet/extension-base/koni/api/xcm';
9
- import { YIELD_POOL_STAT_REFRESH_INTERVAL } from '@subwallet/extension-base/koni/api/yield/helper/utils';
10
- import { _getChainNativeTokenSlug } from '@subwallet/extension-base/services/chain-service/utils';
11
- import { YieldStepType, YieldValidationStatus } from '@subwallet/extension-base/types';
12
- import { createPromiseHandler, formatNumber } from '@subwallet/extension-base/utils';
13
- import { t } from 'i18next';
14
- import { BN, BN_TEN, BN_ZERO, noop } from '@polkadot/util';
15
- import BasePoolHandler from "./base.js";
16
- export default class BaseSpecialStakingPoolHandler extends BasePoolHandler {
17
- /** Pool's type */
18
-
19
- /** Exchange rate before divine with decimals */
20
- rate = 0;
21
- constructor(state, chain) {
22
- super(state, chain);
23
- this.exchangeRatePromise = createPromiseHandler();
24
- }
25
- get metadataInfo() {
26
- return {
27
- altInputAssets: this.altInputAsset,
28
- derivativeAssets: this.derivativeAssets,
29
- inputAsset: this.inputAsset,
30
- rewardAssets: this.rewardAssets,
31
- feeAssets: this.feeAssets,
32
- logo: this.logo,
33
- shortName: this.shortName,
34
- name: this.name,
35
- isAvailable: true,
36
- maintainAsset: this.nativeToken.slug,
37
- maintainBalance: this.maintainBalance,
38
- availableMethod: this.availableMethod
39
- };
40
- }
41
- updateExchangeRate(rate) {
42
- this.rate = rate;
43
- this.exchangeRatePromise.resolve(true);
44
- }
45
- async getExchangeRate() {
46
- await this.exchangeRatePromise.promise;
47
- return this.rate;
48
- }
49
- get isPoolSupportAlternativeFee() {
50
- return this.feeAssets.length > 1;
51
- }
52
- async earlyValidate(request) {
53
- var _poolInfo$statistic;
54
- const poolInfo = await this.getPoolInfo();
55
- if (!poolInfo || !((_poolInfo$statistic = poolInfo.statistic) !== null && _poolInfo$statistic !== void 0 && _poolInfo$statistic.earningThreshold.join)) {
56
- return {
57
- passed: false,
58
- errorMessage: 'There\'s a trouble fetching data, please check your internet connection and try again'
59
- };
60
- }
61
- if (request.address === ALL_ACCOUNT_KEY) {
62
- return {
63
- passed: true
64
- };
65
- }
66
- const feeAssetInfo = this.state.chainService.getAssetBySlug(this.feeAssets[0]);
67
- const altInputAssetInfo = this.state.chainService.getAssetBySlug(this.altInputAsset);
68
- const inputAssetInfo = this.state.chainService.getAssetBySlug(this.inputAsset);
69
- const [inputAssetBalance, altInputAssetBalance, feeAssetBalance] = await Promise.all([this.state.balanceService.getTokenFreeBalance(request.address, inputAssetInfo.originChain, inputAssetInfo.slug), altInputAssetInfo ? this.state.balanceService.getTokenFreeBalance(request.address, altInputAssetInfo.originChain, altInputAssetInfo.slug) : Promise.resolve({
70
- symbol: '',
71
- decimals: 0,
72
- value: '0'
73
- }), this.state.balanceService.getTokenFreeBalance(request.address, feeAssetInfo.originChain, feeAssetInfo.slug)]);
74
- const bnInputAssetBalance = new BN(inputAssetBalance.value);
75
- const bnAltInputAssetBalance = new BN(altInputAssetBalance.value);
76
- const bnMinJoinPool = new BN(poolInfo.statistic.earningThreshold.join);
77
- const inputTokenInfo = this.state.chainService.getAssetBySlug(this.inputAsset);
78
- const altInputTokenInfo = this.state.chainService.getAssetBySlug(this.altInputAsset);
79
- const minJoinDiv = BN_TEN.pow(new BN(inputAssetInfo.decimals || 0));
80
- const parsedMinJoinPool = bnMinJoinPool.div(minJoinDiv);
81
- if (bnInputAssetBalance.add(bnAltInputAssetBalance).lt(bnMinJoinPool)) {
82
- const originChain = this.state.getChainInfo(inputTokenInfo.originChain);
83
- const altChain = this.state.getChainInfo(altInputTokenInfo.originChain);
84
- return {
85
- passed: false,
86
- errorMessage: `You need at least ${parsedMinJoinPool.toString()} ${inputTokenInfo.symbol} (${originChain.name}) or ${altInputTokenInfo.symbol} (${altChain.name}) to start earning`
87
- };
88
- }
89
- if (this.feeAssets.length === 1) {
90
- const bnFeeAssetBalance = new BN(feeAssetBalance.value);
91
- const minFeeAssetBalance = new BN(this.maintainBalance || '0');
92
- const feeAssetDiv = BN_TEN.pow(new BN(feeAssetInfo.decimals || 0));
93
- const parsedMinFeeAssetBalance = minFeeAssetBalance.div(feeAssetDiv).mul(new BN(12)).div(BN_TEN);
94
- if (bnFeeAssetBalance.lte(BN_ZERO)) {
95
- const feeChain = this.state.getChainInfo(feeAssetInfo.originChain);
96
- return {
97
- passed: false,
98
- errorMessage: `You need at least ${parsedMinFeeAssetBalance.toString()} ${feeAssetInfo.symbol} (${feeChain.name}) to start earning`
99
- };
100
- }
101
- }
102
- return {
103
- passed: true
104
- };
105
- }
106
- get group() {
107
- const inputAsset = this.state.getAssetBySlug(this.inputAsset);
108
- const groupSlug = inputAsset.multiChainAsset;
109
- return groupSlug || this.inputAsset;
110
- }
111
-
112
- /* Subscribe pool info */
113
-
114
- async subscribePoolInfo(callback) {
115
- let cancel = false;
116
- const getStatInterval = () => {
117
- if (!this.isActive) {
118
- if (!cancel) {
119
- const rs = {
120
- ...this.baseInfo,
121
- type: this.type,
122
- metadata: {
123
- ...this.metadataInfo,
124
- description: this.getDescription()
125
- }
126
- };
127
- callback(rs);
128
- }
129
- } else {
130
- this.getPoolStat().then(rs => {
131
- if (!cancel) {
132
- callback(rs);
133
- }
134
- }).catch(console.error);
135
- }
136
- };
137
- getStatInterval();
138
- const interval = setInterval(() => {
139
- if (cancel) {
140
- clearInterval(interval);
141
- } else {
142
- getStatInterval();
143
- }
144
- }, YIELD_POOL_STAT_REFRESH_INTERVAL);
145
- return new Promise(resolve => {
146
- const rs = () => {
147
- cancel = true;
148
- clearInterval(interval);
149
- };
150
- resolve(rs);
151
- });
152
- }
153
-
154
- /* Subscribe pool info */
155
-
156
- /* Get pool reward */
157
-
158
- async getPoolReward() {
159
- return new Promise(resolve => resolve(noop));
160
- }
161
- async getPoolRewardHistory() {
162
- return new Promise(resolve => resolve(noop));
163
- }
164
-
165
- /* Get pool reward */
166
-
167
- /* Get pool targets */
168
-
169
- async getPoolTargets() {
170
- return new Promise(resolve => resolve([]));
171
- }
172
-
173
- /* Get pool targets */
174
-
175
- /* Join pool action */
176
-
177
- /* Generate steps */
178
-
179
- /**
180
- * @async
181
- * @function getXcmStep
182
- * */
183
- async getXcmStep(params) {
184
- const {
185
- address,
186
- amount
187
- } = params;
188
- const bnAmount = new BN(amount);
189
- const inputTokenSlug = this.inputAsset; // assume that the pool only has 1 input token, will update later
190
- const inputTokenInfo = this.state.getAssetBySlug(inputTokenSlug);
191
- const inputTokenBalance = await this.state.balanceService.getTokenFreeBalance(address, inputTokenInfo.originChain, inputTokenSlug);
192
- const bnInputTokenBalance = new BN(inputTokenBalance.value);
193
- if (!bnInputTokenBalance.gte(bnAmount)) {
194
- if (this.altInputAsset) {
195
- const altInputTokenSlug = this.altInputAsset;
196
- const altInputTokenInfo = this.state.getAssetBySlug(altInputTokenSlug);
197
- const altInputTokenBalance = await this.state.balanceService.getTokenFreeBalance(address, altInputTokenInfo.originChain, altInputTokenSlug);
198
- const bnAltInputTokenBalance = new BN(altInputTokenBalance.value || '0');
199
- if (bnAltInputTokenBalance.gt(BN_ZERO)) {
200
- const step = {
201
- metadata: {
202
- sendingValue: bnAmount.toString(),
203
- originTokenInfo: altInputTokenInfo,
204
- destinationTokenInfo: inputTokenInfo
205
- },
206
- name: 'Transfer DOT from Polkadot',
207
- type: YieldStepType.XCM
208
- };
209
- const xcmOriginSubstrateApi = await this.state.getSubstrateApi(altInputTokenInfo.originChain).isReady;
210
- const xcmTransfer = await createXcmExtrinsic({
211
- originTokenInfo: altInputTokenInfo,
212
- destinationTokenInfo: inputTokenInfo,
213
- sendingValue: bnAmount.toString(),
214
- recipient: address,
215
- chainInfoMap: this.state.getChainInfoMap(),
216
- substrateApi: xcmOriginSubstrateApi
217
- });
218
- const _xcmFeeInfo = await xcmTransfer.paymentInfo(address);
219
- const xcmFeeInfo = _xcmFeeInfo.toPrimitive();
220
- // TODO: calculate fee for destination chain
221
-
222
- const fee = {
223
- slug: altInputTokenSlug,
224
- amount: Math.round(xcmFeeInfo.partialFee * 1.2).toString() // TODO
225
- };
226
-
227
- return [step, fee];
228
- }
229
- }
230
- }
231
- return undefined;
232
- }
233
- get defaultSubmitStep() {
234
- return [this.submitJoinStepInfo, {
235
- slug: this.feeAssets[0],
236
- amount: '0'
237
- }];
238
- }
239
-
240
- /**
241
- * @function submitJoinStepInfo
242
- * @description Base info of submit step
243
- * @return Fee of the submitting step
244
- * */
245
-
246
- async getSubmitStep(params) {
247
- const fee = await this.getSubmitStepFee(params);
248
- return [this.submitJoinStepInfo, fee];
249
- }
250
-
251
- /* Generate steps */
252
-
253
- /* Validate join action */
254
-
255
- async validateTokenApproveStep(params, path) {
256
- return Promise.resolve([new TransactionError(BasicTxErrorType.UNSUPPORTED)]);
257
- }
258
- async validateXcmStep(params, path, bnInputTokenBalance) {
259
- const processValidation = {
260
- ok: true,
261
- status: YieldValidationStatus.OK
262
- };
263
- const bnAmount = new BN(params.amount);
264
- const altInputTokenSlug = this.altInputAsset || '';
265
- const altInputTokenInfo = this.state.getAssetBySlug(altInputTokenSlug);
266
- const altInputTokenBalance = await this.state.balanceService.getTokenFreeBalance(params.address, altInputTokenInfo.originChain, altInputTokenSlug);
267
- const missingAmount = bnAmount.sub(bnInputTokenBalance); // TODO: what if input token is not LOCAL ??
268
- const xcmFee = new BN(path.totalFee[1].amount || '0');
269
- const xcmAmount = missingAmount.add(xcmFee);
270
- const bnAltInputTokenBalance = new BN(altInputTokenBalance.value || '0');
271
- const altInputTokenMinAmount = new BN(altInputTokenInfo.minAmount || '0');
272
- if (!bnAltInputTokenBalance.sub(xcmAmount).gte(altInputTokenMinAmount)) {
273
- processValidation.failedStep = path.steps[1];
274
- processValidation.ok = false;
275
- processValidation.status = YieldValidationStatus.NOT_ENOUGH_BALANCE;
276
- return [new TransactionError(YieldValidationStatus.NOT_ENOUGH_BALANCE, processValidation.message, processValidation)];
277
- }
278
- return [];
279
- }
280
- async validateJoinStep(id, params, path, bnInputTokenBalance, isXcmOk) {
281
- const _poolInfo = await this.getPoolInfo();
282
- if (!_poolInfo) {
283
- return [new TransactionError(BasicTxErrorType.INTERNAL_ERROR)];
284
- }
285
- const poolInfo = _poolInfo;
286
- if (!poolInfo.statistic) {
287
- return [new TransactionError(BasicTxErrorType.INTERNAL_ERROR)];
288
- }
289
- const processValidation = {
290
- ok: true,
291
- status: YieldValidationStatus.OK
292
- };
293
- const feeTokenSlug = path.totalFee[id].slug;
294
- const feeTokenInfo = this.state.getAssetBySlug(feeTokenSlug);
295
- const defaultFeeTokenSlug = this.feeAssets[0];
296
- const bnAmount = new BN(params.amount);
297
- if (this.feeAssets.length === 1 && feeTokenSlug === defaultFeeTokenSlug) {
298
- var _path$totalFee$id;
299
- const bnFeeAmount = new BN(((_path$totalFee$id = path.totalFee[id]) === null || _path$totalFee$id === void 0 ? void 0 : _path$totalFee$id.amount) || '0');
300
- const feeTokenBalance = await this.state.balanceService.getTokenFreeBalance(params.address, feeTokenInfo.originChain, feeTokenSlug);
301
- const bnFeeTokenBalance = new BN(feeTokenBalance.value || '0');
302
- const bnFeeTokenMinAmount = new BN((feeTokenInfo === null || feeTokenInfo === void 0 ? void 0 : feeTokenInfo.minAmount) || '0');
303
- if (!bnFeeTokenBalance.sub(bnFeeAmount).gte(bnFeeTokenMinAmount)) {
304
- processValidation.failedStep = path.steps[id];
305
- processValidation.ok = false;
306
- processValidation.status = YieldValidationStatus.NOT_ENOUGH_FEE;
307
- return [new TransactionError(YieldValidationStatus.NOT_ENOUGH_FEE, processValidation.message, processValidation)];
308
- }
309
- }
310
- if (!bnAmount.gte(new BN(poolInfo.statistic.earningThreshold.join || '0'))) {
311
- processValidation.failedStep = path.steps[id];
312
- processValidation.ok = false;
313
- processValidation.status = YieldValidationStatus.NOT_ENOUGH_MIN_JOIN_POOL;
314
- return [new TransactionError(YieldValidationStatus.NOT_ENOUGH_MIN_JOIN_POOL, processValidation.message, processValidation)];
315
- }
316
- if (!isXcmOk && bnAmount.gt(bnInputTokenBalance)) {
317
- processValidation.failedStep = path.steps[id];
318
- processValidation.ok = false;
319
- processValidation.status = YieldValidationStatus.NOT_ENOUGH_BALANCE;
320
- return [new TransactionError(YieldValidationStatus.NOT_ENOUGH_BALANCE, processValidation.message, processValidation)];
321
- }
322
- return [];
323
- }
324
- async validateYieldJoin(params, path) {
325
- const inputTokenSlug = this.inputAsset;
326
- const inputTokenInfo = this.state.getAssetBySlug(inputTokenSlug);
327
- const balanceService = this.state.balanceService;
328
- const inputTokenBalance = await balanceService.getTokenFreeBalance(params.address, inputTokenInfo.originChain, inputTokenSlug);
329
- const bnInputTokenBalance = new BN(inputTokenBalance.value || '0');
330
- const bnAmount = new BN(params.amount);
331
- if (bnAmount.lte(BN_ZERO)) {
332
- return [new TransactionError(BasicTxErrorType.INVALID_PARAMS, 'Amount must be greater than 0')];
333
- }
334
- let isXcmOk = false;
335
- for (const step of path.steps) {
336
- const getErrors = async () => {
337
- switch (step.type) {
338
- case YieldStepType.DEFAULT:
339
- return Promise.resolve([]);
340
- case YieldStepType.XCM:
341
- return this.validateXcmStep(params, path, bnInputTokenBalance);
342
- case YieldStepType.TOKEN_APPROVAL:
343
- return this.validateTokenApproveStep(params, path);
344
- default:
345
- return this.validateJoinStep(step.id, params, path, bnInputTokenBalance, isXcmOk);
346
- }
347
- };
348
- const errors = await getErrors();
349
- if (errors.length) {
350
- return errors;
351
- } else if (step.type === YieldStepType.XCM) {
352
- isXcmOk = true;
353
- }
354
- }
355
- return [];
356
- }
357
-
358
- /* Validate join action */
359
-
360
- /* Submit join action */
361
-
362
- async handleTokenApproveStep(data, path) {
363
- return Promise.reject(new TransactionError(BasicTxErrorType.UNSUPPORTED));
364
- }
365
- async handleXcmStep(data, path, xcmFee) {
366
- const {
367
- address,
368
- amount
369
- } = data;
370
- const destinationTokenSlug = this.inputAsset;
371
- const originChainInfo = this.state.getChainInfo(COMMON_CHAIN_SLUGS.POLKADOT);
372
- const originTokenSlug = _getChainNativeTokenSlug(originChainInfo);
373
- const originTokenInfo = this.state.getAssetBySlug(originTokenSlug);
374
- const destinationTokenInfo = this.state.getAssetBySlug(destinationTokenSlug);
375
- const substrateApi = this.state.getSubstrateApi(originChainInfo.slug);
376
- const inputTokenBalance = await this.state.balanceService.getTokenFreeBalance(address, destinationTokenInfo.originChain, destinationTokenSlug);
377
- const bnInputTokenBalance = new BN(inputTokenBalance.value);
378
- const bnXcmFee = new BN(xcmFee);
379
- const bnAmount = new BN(amount);
380
- const bnTotalAmount = bnAmount.sub(bnInputTokenBalance).add(bnXcmFee);
381
- const extrinsic = await createXcmExtrinsic({
382
- chainInfoMap: this.state.getChainInfoMap(),
383
- destinationTokenInfo,
384
- originTokenInfo,
385
- recipient: address,
386
- sendingValue: bnTotalAmount.toString(),
387
- substrateApi
388
- });
389
- const xcmData = {
390
- originNetworkKey: originChainInfo.slug,
391
- destinationNetworkKey: destinationTokenInfo.originChain,
392
- from: address,
393
- to: address,
394
- value: bnTotalAmount.toString(),
395
- tokenSlug: originTokenSlug,
396
- showExtraWarning: true
397
- };
398
- return {
399
- txChain: originChainInfo.slug,
400
- extrinsicType: ExtrinsicType.TRANSFER_XCM,
401
- extrinsic,
402
- txData: xcmData,
403
- transferNativeAmount: bnTotalAmount.toString()
404
- };
405
- }
406
- handleYieldJoin(data, path, currentStep) {
407
- const type = path.steps[currentStep].type;
408
- switch (type) {
409
- case YieldStepType.DEFAULT:
410
- return Promise.reject(new TransactionError(BasicTxErrorType.UNSUPPORTED));
411
- case YieldStepType.TOKEN_APPROVAL:
412
- return this.handleTokenApproveStep(data, path);
413
- case YieldStepType.XCM:
414
- {
415
- const xcmFee = path.totalFee[currentStep].amount || '0';
416
- return this.handleXcmStep(data, path, xcmFee);
417
- }
418
- default:
419
- return this.handleSubmitStep(data, path);
420
- }
421
- }
422
-
423
- /* Submit join action */
424
-
425
- /* Join pool action */
426
-
427
- /* Leave pool action */
428
-
429
- async validateYieldLeave(amount, address, fastLeave, selectedTarget) {
430
- const poolInfo = await this.getPoolInfo();
431
- const poolPosition = await this.getPoolPosition(address);
432
- if (!poolInfo || !poolInfo.statistic || !poolPosition) {
433
- return [new TransactionError(BasicTxErrorType.INTERNAL_ERROR)];
434
- }
435
- if (!this.availableMethod.defaultUnstake && !fastLeave) {
436
- return [new TransactionError(BasicTxErrorType.INTERNAL_ERROR)];
437
- }
438
- if (!this.availableMethod.fastUnstake && fastLeave) {
439
- return [new TransactionError(BasicTxErrorType.INTERNAL_ERROR)];
440
- }
441
- const errors = [];
442
- const bnActiveStake = new BN(poolPosition.activeStake);
443
- const bnAmount = new BN(amount);
444
- const bnRemainingStake = bnActiveStake.sub(bnAmount);
445
- const minStake = new BN(poolInfo.statistic.earningThreshold.join || '0');
446
- const minUnstake = new BN((fastLeave ? poolInfo.statistic.earningThreshold.fastUnstake : poolInfo.statistic.earningThreshold.defaultUnstake) || '0');
447
- const maxUnstakeRequest = poolInfo.statistic.maxWithdrawalRequestPerFarmer;
448
- const derivativeTokenInfo = this.state.getAssetBySlug(this.derivativeAssets[0]);
449
- if (bnAmount.lte(BN_ZERO)) {
450
- return [new TransactionError(BasicTxErrorType.INVALID_PARAMS, t('Amount must be greater than 0'))];
451
- }
452
- if (bnAmount.lt(minUnstake)) {
453
- const minUnstakeStr = formatNumber(minUnstake.toString(), derivativeTokenInfo.decimals || 0);
454
- errors.push(new TransactionError(StakingTxErrorType.NOT_ENOUGH_MIN_UNSTAKE, t('You need to unstake at least {{amount}} {{token}}', {
455
- replace: {
456
- amount: minUnstakeStr,
457
- token: derivativeTokenInfo.symbol
458
- }
459
- })));
460
- }
461
- if (!fastLeave) {
462
- if (!(bnRemainingStake.isZero() || bnRemainingStake.gte(minStake))) {
463
- errors.push(new TransactionError(StakingTxErrorType.INVALID_ACTIVE_STAKE)); // TODO
464
- }
465
-
466
- if (poolPosition.unstakings.length > maxUnstakeRequest) {
467
- errors.push(new TransactionError(StakingTxErrorType.EXCEED_MAX_UNSTAKING, t('You cannot unstake more than {{number}} times', {
468
- replace: {
469
- number: maxUnstakeRequest
470
- }
471
- })));
472
- }
473
- }
474
- return Promise.resolve(errors);
475
- }
476
- handleYieldUnstake(amount, address, selectedTarget) {
477
- return Promise.reject(new TransactionError(BasicTxErrorType.UNSUPPORTED));
478
- }
479
-
480
- /* Leave pool action */
481
-
482
- /* Other action */
483
-
484
- handleYieldCancelUnstake() {
485
- return Promise.reject(new TransactionError(BasicTxErrorType.UNSUPPORTED));
486
- }
487
- handleYieldClaimReward(address, bondReward) {
488
- return Promise.reject(new TransactionError(BasicTxErrorType.UNSUPPORTED));
489
- }
490
- handleYieldWithdraw(address, unstakingInfo) {
491
- return Promise.reject(new TransactionError(BasicTxErrorType.UNSUPPORTED));
492
- }
493
-
494
- /* Other actions */
495
- }
@@ -1,45 +0,0 @@
1
- import { TransactionError } from '@subwallet/extension-base/background/errors/TransactionError';
2
- import { ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
3
- import KoniState from '@subwallet/extension-base/koni/background/handlers/State';
4
- import { EarningRewardHistoryItem, EarningRewardItem, EarningRewardJson, HandleYieldStepData, HandleYieldStepParams, OptimalYieldPath, OptimalYieldPathParams, RequestEarlyValidateYield, RequestStakeCancelWithdrawal, RequestStakeClaimReward, RequestYieldLeave, RequestYieldWithdrawal, ResponseEarlyValidateYield, TransactionData, ValidateYieldProcessParams, YieldPoolInfo, YieldPoolTarget, YieldPositionInfo } from '@subwallet/extension-base/types';
5
- import { BehaviorSubject } from 'rxjs';
6
- import { BasePoolHandler } from './handlers';
7
- export default class EarningService {
8
- protected readonly state: KoniState;
9
- protected handlers: Record<string, BasePoolHandler>;
10
- private earningRewardSubject;
11
- private earningRewardHistorySubject;
12
- private minAmountPercentSubject;
13
- constructor(state: KoniState);
14
- private initHandlers;
15
- getPoolHandler(slug: string): BasePoolHandler | undefined;
16
- isPoolSupportAlternativeFee(slug: string): boolean;
17
- subscribeMinAmountPercent(): BehaviorSubject<Record<string, number>>;
18
- getMinAmountPercent(): Record<string, number>;
19
- subscribePoolsInfo(callback: (rs: YieldPoolInfo) => void): Promise<VoidFunction>;
20
- subscribePoolPositions(addresses: string[], callback: (rs: YieldPositionInfo) => void): Promise<VoidFunction>;
21
- updateEarningReward(stakingRewardData: EarningRewardItem): void;
22
- getPoolReward(addresses: string[], callback: (result: EarningRewardItem) => void): Promise<VoidFunction>;
23
- subscribeEarningReward(): BehaviorSubject<EarningRewardJson>;
24
- getEarningRewards(): EarningRewardJson;
25
- fetchPoolRewardHistory(addresses: string[], callback: (result: EarningRewardHistoryItem) => void): Promise<VoidFunction>;
26
- updateEarningRewardHistory(earningRewardHistory: EarningRewardHistoryItem): void;
27
- subscribeEarningRewardHistory(): BehaviorSubject<Record<string, EarningRewardHistoryItem>>;
28
- getEarningRewardHistory(): Record<string, EarningRewardHistoryItem>;
29
- /**
30
- * @async
31
- * @function getPoolTargets
32
- * @param {string} slug - Pool's slug
33
- * @return {Promise<YieldPoolTarget[]>} List of pool's target
34
- * */
35
- getPoolTargets(slug: string): Promise<YieldPoolTarget[]>;
36
- earlyValidateJoin(request: RequestEarlyValidateYield): Promise<ResponseEarlyValidateYield>;
37
- generateOptimalSteps(params: OptimalYieldPathParams): Promise<OptimalYieldPath>;
38
- validateYieldJoin(params: ValidateYieldProcessParams): Promise<TransactionError[]>;
39
- handleYieldJoin(params: HandleYieldStepParams): Promise<HandleYieldStepData>;
40
- validateYieldLeave(params: RequestYieldLeave): Promise<TransactionError[]>;
41
- handleYieldLeave(params: RequestYieldLeave): Promise<[ExtrinsicType, TransactionData]>;
42
- handleYieldWithdraw(params: RequestYieldWithdrawal): Promise<TransactionData>;
43
- handleYieldCancelUnstake(params: RequestStakeCancelWithdrawal): Promise<TransactionData>;
44
- handleYieldClaimReward(params: RequestStakeClaimReward): Promise<TransactionData>;
45
- }