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