@subwallet/extension-base 1.1.28-1 → 1.1.28-beta.2

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 (289) hide show
  1. package/background/KoniTypes.d.ts +94 -68
  2. package/background/KoniTypes.js +16 -13
  3. package/background/errors/TransactionError.js +9 -0
  4. package/cjs/background/KoniTypes.js +17 -16
  5. package/cjs/background/errors/TransactionError.js +9 -0
  6. package/cjs/constants/index.js +9 -3
  7. package/cjs/koni/api/nft/config.js +33 -23
  8. package/cjs/koni/api/nft/index.js +14 -0
  9. package/cjs/koni/api/nft/nft.js +1 -22
  10. package/cjs/koni/api/nft/ordinal_nft/constants.js +21 -0
  11. package/cjs/koni/api/nft/ordinal_nft/index.js +121 -0
  12. package/cjs/koni/api/nft/ordinal_nft/utils.js +41 -0
  13. package/cjs/koni/api/staking/bonding/amplitude.js +17 -15
  14. package/cjs/koni/api/staking/bonding/astar.js +11 -10
  15. package/cjs/koni/api/staking/bonding/index.js +4 -1
  16. package/cjs/koni/api/staking/bonding/paraChain.js +25 -23
  17. package/cjs/koni/api/staking/bonding/relayChain.js +48 -45
  18. package/cjs/koni/api/staking/bonding/utils.js +104 -86
  19. package/cjs/koni/api/staking/index.js +6 -5
  20. package/cjs/koni/api/staking/paraChain.js +6 -5
  21. package/cjs/koni/api/staking/relayChain.js +3 -2
  22. package/cjs/koni/api/yield/helper/utils.js +46 -0
  23. package/cjs/koni/background/cron.js +2 -0
  24. package/cjs/koni/background/handlers/Extension.js +347 -69
  25. package/cjs/koni/background/handlers/State.js +57 -4
  26. package/cjs/koni/background/handlers/index.js +4 -2
  27. package/cjs/koni/background/subscription.js +89 -19
  28. package/cjs/services/campaign-service/index.js +9 -6
  29. package/cjs/services/chain-service/constants.js +2 -16
  30. package/cjs/services/chain-service/utils.js +7 -1
  31. package/cjs/services/earning-service/constants/chains.js +29 -0
  32. package/cjs/services/earning-service/constants/index.js +27 -0
  33. package/cjs/services/earning-service/constants/step.js +18 -0
  34. package/cjs/services/earning-service/handlers/base.js +220 -0
  35. package/cjs/services/earning-service/handlers/index.js +60 -0
  36. package/cjs/services/earning-service/handlers/lending/base.js +20 -0
  37. package/cjs/services/earning-service/handlers/lending/index.js +13 -0
  38. package/cjs/services/earning-service/handlers/lending/interlay.js +170 -0
  39. package/cjs/services/earning-service/handlers/liquid-staking/acala.js +198 -0
  40. package/cjs/services/earning-service/handlers/liquid-staking/base.js +43 -0
  41. package/cjs/services/earning-service/handlers/liquid-staking/bifrost.js +259 -0
  42. package/cjs/services/earning-service/handlers/liquid-staking/index.js +34 -0
  43. package/cjs/services/earning-service/handlers/liquid-staking/parallel.js +182 -0
  44. package/cjs/services/earning-service/handlers/liquid-staking/stella-swap.js +375 -0
  45. package/cjs/services/earning-service/handlers/native-staking/amplitude.js +373 -0
  46. package/cjs/services/earning-service/handlers/native-staking/astar.js +446 -0
  47. package/cjs/services/earning-service/handlers/native-staking/base-para.js +137 -0
  48. package/cjs/services/earning-service/handlers/native-staking/base.js +119 -0
  49. package/cjs/services/earning-service/handlers/native-staking/index.js +34 -0
  50. package/cjs/services/earning-service/handlers/native-staking/para-chain.js +375 -0
  51. package/cjs/services/earning-service/handlers/native-staking/relay-chain.js +529 -0
  52. package/cjs/services/earning-service/handlers/nomination-pool/index.js +521 -0
  53. package/cjs/services/earning-service/handlers/special.js +411 -0
  54. package/cjs/services/earning-service/service.js +351 -0
  55. package/cjs/services/earning-service/utils/index.js +128 -0
  56. package/cjs/services/event-service/index.js +4 -0
  57. package/cjs/services/keyring-service/index.js +14 -2
  58. package/cjs/services/migration-service/scripts/DeleteEarningData.js +21 -0
  59. package/cjs/services/migration-service/scripts/EnableEarningChains.js +21 -0
  60. package/cjs/services/migration-service/scripts/MigrateLedgerAccount.js +1 -1
  61. package/cjs/services/migration-service/scripts/MigrateTransactionHistory.js +1 -1
  62. package/cjs/services/migration-service/scripts/databases/MigrateEarningHistory.js +21 -0
  63. package/cjs/services/migration-service/scripts/databases/MigrateEarningVersion.js +21 -0
  64. package/cjs/services/migration-service/scripts/index.js +7 -1
  65. package/cjs/services/mint-campaign-service/campaigns/UnlockDotCampaign.js +149 -0
  66. package/cjs/services/mint-campaign-service/campaigns/index.js +13 -0
  67. package/cjs/services/mint-campaign-service/constants.js +11 -0
  68. package/cjs/services/mint-campaign-service/index.js +18 -0
  69. package/cjs/services/notification-service/NotificationService.js +1 -1
  70. package/cjs/services/storage-service/DatabaseService.js +51 -0
  71. package/cjs/services/storage-service/databases/index.js +4 -0
  72. package/cjs/services/storage-service/db-stores/NominatorMetadata.js +3 -3
  73. package/cjs/services/storage-service/db-stores/YieldPoolStore.js +36 -0
  74. package/cjs/services/storage-service/db-stores/YieldPositionStore.js +65 -0
  75. package/cjs/services/transaction-service/event-parser/index.js +58 -0
  76. package/cjs/services/transaction-service/helpers/index.js +3 -1
  77. package/cjs/services/transaction-service/index.js +180 -74
  78. package/cjs/services/transaction-service/utils.js +1 -0
  79. package/cjs/types/campaigns/index.js +16 -0
  80. package/cjs/types/campaigns/unlock-dot.js +1 -0
  81. package/cjs/types/index.js +44 -0
  82. package/cjs/types/ordinal.js +1 -0
  83. package/cjs/types/transaction.js +1 -0
  84. package/cjs/types/yield/actions/index.js +27 -0
  85. package/cjs/types/yield/actions/join/index.js +38 -0
  86. package/cjs/types/yield/actions/join/step.js +47 -0
  87. package/cjs/types/yield/actions/join/submit.js +1 -0
  88. package/cjs/types/yield/actions/join/validate.js +16 -0
  89. package/cjs/types/yield/actions/others.js +1 -0
  90. package/cjs/types/yield/index.js +27 -0
  91. package/cjs/types/yield/info/account/index.js +49 -0
  92. package/cjs/types/yield/info/account/info.js +1 -0
  93. package/cjs/types/yield/info/account/reward.js +1 -0
  94. package/cjs/types/yield/info/account/target.js +32 -0
  95. package/cjs/types/yield/info/account/unstake.js +27 -0
  96. package/cjs/types/yield/info/base.js +41 -0
  97. package/cjs/types/yield/info/chain/index.js +27 -0
  98. package/cjs/types/yield/info/chain/info.js +1 -0
  99. package/cjs/types/yield/info/chain/target.js +1 -0
  100. package/cjs/types/yield/info/index.js +49 -0
  101. package/cjs/types/yield/info/pallet.js +15 -0
  102. package/cjs/utils/fetchStaticData.js +2 -1
  103. package/cjs/utils/index.js +89 -1
  104. package/cjs/utils/object.js +12 -0
  105. package/cjs/utils/yield/index.js +3 -0
  106. package/constants/index.d.ts +2 -0
  107. package/constants/index.js +2 -0
  108. package/koni/api/nft/config.js +33 -23
  109. package/koni/api/nft/index.js +15 -1
  110. package/koni/api/nft/nft.js +2 -23
  111. package/koni/api/nft/ordinal_nft/constants.d.ts +9 -0
  112. package/koni/api/nft/ordinal_nft/constants.js +12 -0
  113. package/koni/api/nft/ordinal_nft/index.d.ts +8 -0
  114. package/koni/api/nft/ordinal_nft/index.js +114 -0
  115. package/koni/api/nft/ordinal_nft/utils.d.ts +2 -0
  116. package/koni/api/nft/ordinal_nft/utils.js +33 -0
  117. package/koni/api/staking/bonding/amplitude.js +11 -9
  118. package/koni/api/staking/bonding/astar.js +9 -8
  119. package/koni/api/staking/bonding/index.d.ts +1 -1
  120. package/koni/api/staking/bonding/index.js +5 -1
  121. package/koni/api/staking/bonding/paraChain.js +12 -10
  122. package/koni/api/staking/bonding/relayChain.d.ts +2 -2
  123. package/koni/api/staking/bonding/relayChain.js +33 -30
  124. package/koni/api/staking/bonding/utils.d.ts +15 -38
  125. package/koni/api/staking/bonding/utils.js +85 -69
  126. package/koni/api/staking/index.js +2 -1
  127. package/koni/api/staking/paraChain.js +7 -6
  128. package/koni/api/staking/relayChain.js +4 -3
  129. package/koni/api/yield/helper/utils.d.ts +10 -0
  130. package/koni/api/yield/helper/utils.js +32 -0
  131. package/koni/background/cron.js +2 -0
  132. package/koni/background/handlers/Extension.d.ts +16 -1
  133. package/koni/background/handlers/Extension.js +306 -30
  134. package/koni/background/handlers/State.d.ts +18 -2
  135. package/koni/background/handlers/State.js +56 -4
  136. package/koni/background/handlers/index.js +4 -2
  137. package/koni/background/subscription.d.ts +5 -1
  138. package/koni/background/subscription.js +91 -21
  139. package/package.json +317 -4
  140. package/services/campaign-service/index.js +9 -6
  141. package/services/chain-service/constants.d.ts +0 -11
  142. package/services/chain-service/constants.js +1 -14
  143. package/services/chain-service/utils.d.ts +1 -0
  144. package/services/chain-service/utils.js +5 -1
  145. package/services/earning-service/constants/abis/compound_finance_v2_abi.json +1235 -0
  146. package/services/earning-service/constants/abis/st_liquid_token_abi.json +1355 -0
  147. package/services/earning-service/constants/chains.d.ts +14 -0
  148. package/services/earning-service/constants/chains.js +21 -0
  149. package/services/earning-service/constants/index.d.ts +2 -0
  150. package/services/earning-service/constants/index.js +5 -0
  151. package/services/earning-service/constants/step.d.ts +3 -0
  152. package/services/earning-service/constants/step.js +10 -0
  153. package/services/earning-service/handlers/base.d.ts +107 -0
  154. package/services/earning-service/handlers/base.js +213 -0
  155. package/services/earning-service/handlers/index.d.ts +5 -0
  156. package/services/earning-service/handlers/index.js +8 -0
  157. package/services/earning-service/handlers/lending/base.d.ts +6 -0
  158. package/services/earning-service/handlers/lending/base.js +12 -0
  159. package/services/earning-service/handlers/lending/index.d.ts +1 -0
  160. package/services/earning-service/handlers/lending/index.js +4 -0
  161. package/services/earning-service/handlers/lending/interlay.d.ts +22 -0
  162. package/services/earning-service/handlers/lending/interlay.js +162 -0
  163. package/services/earning-service/handlers/liquid-staking/acala.d.ts +27 -0
  164. package/services/earning-service/handlers/liquid-staking/acala.js +190 -0
  165. package/services/earning-service/handlers/liquid-staking/base.d.ts +9 -0
  166. package/services/earning-service/handlers/liquid-staking/base.js +35 -0
  167. package/services/earning-service/handlers/liquid-staking/bifrost.d.ts +44 -0
  168. package/services/earning-service/handlers/liquid-staking/bifrost.js +248 -0
  169. package/services/earning-service/handlers/liquid-staking/index.d.ts +4 -0
  170. package/services/earning-service/handlers/liquid-staking/index.js +7 -0
  171. package/services/earning-service/handlers/liquid-staking/parallel.d.ts +27 -0
  172. package/services/earning-service/handlers/liquid-staking/parallel.js +174 -0
  173. package/services/earning-service/handlers/liquid-staking/stella-swap.d.ts +36 -0
  174. package/services/earning-service/handlers/liquid-staking/stella-swap.js +365 -0
  175. package/services/earning-service/handlers/native-staking/amplitude.d.ts +22 -0
  176. package/services/earning-service/handlers/native-staking/amplitude.js +364 -0
  177. package/services/earning-service/handlers/native-staking/astar.d.ts +19 -0
  178. package/services/earning-service/handlers/native-staking/astar.js +436 -0
  179. package/services/earning-service/handlers/native-staking/base-para.d.ts +11 -0
  180. package/services/earning-service/handlers/native-staking/base-para.js +129 -0
  181. package/services/earning-service/handlers/native-staking/base.d.ts +20 -0
  182. package/services/earning-service/handlers/native-staking/base.js +110 -0
  183. package/services/earning-service/handlers/native-staking/index.d.ts +4 -0
  184. package/services/earning-service/handlers/native-staking/index.js +7 -0
  185. package/services/earning-service/handlers/native-staking/para-chain.d.ts +15 -0
  186. package/services/earning-service/handlers/native-staking/para-chain.js +367 -0
  187. package/services/earning-service/handlers/native-staking/relay-chain.d.ts +21 -0
  188. package/services/earning-service/handlers/native-staking/relay-chain.js +520 -0
  189. package/services/earning-service/handlers/nomination-pool/index.d.ts +33 -0
  190. package/services/earning-service/handlers/nomination-pool/index.js +511 -0
  191. package/services/earning-service/handlers/special.d.ts +58 -0
  192. package/services/earning-service/handlers/special.js +403 -0
  193. package/services/earning-service/service.d.ts +40 -0
  194. package/services/earning-service/service.js +343 -0
  195. package/services/earning-service/utils/index.d.ts +18 -0
  196. package/services/earning-service/utils/index.js +112 -0
  197. package/services/event-service/index.d.ts +1 -0
  198. package/services/event-service/index.js +4 -0
  199. package/services/event-service/types.d.ts +8 -0
  200. package/services/keyring-service/index.d.ts +2 -1
  201. package/services/keyring-service/index.js +14 -2
  202. package/services/migration-service/scripts/DeleteEarningData.d.ts +4 -0
  203. package/services/migration-service/scripts/DeleteEarningData.js +13 -0
  204. package/services/migration-service/scripts/EnableEarningChains.d.ts +4 -0
  205. package/services/migration-service/scripts/EnableEarningChains.js +13 -0
  206. package/services/migration-service/scripts/MigrateLedgerAccount.js +1 -1
  207. package/services/migration-service/scripts/MigrateTransactionHistory.js +1 -1
  208. package/services/migration-service/scripts/databases/MigrateEarningHistory.d.ts +4 -0
  209. package/services/migration-service/scripts/databases/MigrateEarningHistory.js +13 -0
  210. package/services/migration-service/scripts/databases/MigrateEarningVersion.d.ts +4 -0
  211. package/services/migration-service/scripts/databases/MigrateEarningVersion.js +13 -0
  212. package/services/migration-service/scripts/index.js +7 -1
  213. package/services/mint-campaign-service/campaigns/UnlockDotCampaign.d.ts +13 -0
  214. package/services/mint-campaign-service/campaigns/UnlockDotCampaign.js +139 -0
  215. package/services/mint-campaign-service/campaigns/index.d.ts +1 -0
  216. package/services/mint-campaign-service/campaigns/index.js +4 -0
  217. package/services/mint-campaign-service/constants.d.ts +1 -0
  218. package/services/mint-campaign-service/constants.js +4 -0
  219. package/services/mint-campaign-service/index.d.ts +7 -0
  220. package/services/mint-campaign-service/index.js +11 -0
  221. package/services/notification-service/NotificationService.js +1 -1
  222. package/services/storage-service/DatabaseService.d.ts +18 -1
  223. package/services/storage-service/DatabaseService.js +51 -0
  224. package/services/storage-service/databases/index.d.ts +3 -1
  225. package/services/storage-service/databases/index.js +4 -0
  226. package/services/storage-service/db-stores/NominatorMetadata.js +3 -3
  227. package/services/storage-service/db-stores/YieldPoolStore.d.ts +10 -0
  228. package/services/storage-service/db-stores/YieldPoolStore.js +28 -0
  229. package/services/storage-service/db-stores/YieldPositionStore.d.ts +9 -0
  230. package/services/storage-service/db-stores/YieldPositionStore.js +57 -0
  231. package/services/subscan-service/index.d.ts +2 -2
  232. package/services/transaction-service/event-parser/index.d.ts +3 -1
  233. package/services/transaction-service/event-parser/index.js +57 -1
  234. package/services/transaction-service/helpers/index.js +3 -1
  235. package/services/transaction-service/index.d.ts +4 -15
  236. package/services/transaction-service/index.js +178 -72
  237. package/services/transaction-service/types.d.ts +2 -0
  238. package/services/transaction-service/utils.js +1 -0
  239. package/types/campaigns/index.d.ts +1 -0
  240. package/types/campaigns/index.js +4 -0
  241. package/types/campaigns/unlock-dot.d.ts +71 -0
  242. package/types/campaigns/unlock-dot.js +1 -0
  243. package/types/index.d.ts +5 -0
  244. package/types/index.js +5 -1
  245. package/types/ordinal.d.ts +69 -0
  246. package/types/ordinal.js +1 -0
  247. package/types/transaction.d.ts +3 -0
  248. package/types/transaction.js +1 -0
  249. package/types/yield/actions/index.d.ts +2 -0
  250. package/types/yield/actions/index.js +5 -0
  251. package/types/yield/actions/join/index.d.ts +3 -0
  252. package/types/yield/actions/join/index.js +6 -0
  253. package/types/yield/actions/join/step.d.ts +94 -0
  254. package/types/yield/actions/join/step.js +46 -0
  255. package/types/yield/actions/join/submit.d.ts +53 -0
  256. package/types/yield/actions/join/submit.js +1 -0
  257. package/types/yield/actions/join/validate.d.ts +18 -0
  258. package/types/yield/actions/join/validate.js +10 -0
  259. package/types/yield/actions/others.d.ts +63 -0
  260. package/types/yield/actions/others.js +1 -0
  261. package/types/yield/index.d.ts +2 -0
  262. package/types/yield/index.js +5 -0
  263. package/types/yield/info/account/index.d.ts +4 -0
  264. package/types/yield/info/account/index.js +7 -0
  265. package/types/yield/info/account/info.d.ts +101 -0
  266. package/types/yield/info/account/info.js +1 -0
  267. package/types/yield/info/account/reward.d.ts +30 -0
  268. package/types/yield/info/account/reward.js +1 -0
  269. package/types/yield/info/account/target.d.ts +43 -0
  270. package/types/yield/info/account/target.js +27 -0
  271. package/types/yield/info/account/unstake.d.ts +31 -0
  272. package/types/yield/info/account/unstake.js +22 -0
  273. package/types/yield/info/base.d.ts +45 -0
  274. package/types/yield/info/base.js +36 -0
  275. package/types/yield/info/chain/index.d.ts +2 -0
  276. package/types/yield/info/chain/index.js +5 -0
  277. package/types/yield/info/chain/info.d.ts +208 -0
  278. package/types/yield/info/chain/info.js +1 -0
  279. package/types/yield/info/chain/target.d.ts +37 -0
  280. package/types/yield/info/chain/target.js +1 -0
  281. package/types/yield/info/index.d.ts +4 -0
  282. package/types/yield/info/index.js +7 -0
  283. package/types/yield/info/pallet.d.ts +143 -0
  284. package/types/yield/info/pallet.js +9 -0
  285. package/utils/fetchStaticData.js +2 -1
  286. package/utils/index.d.ts +5 -0
  287. package/utils/index.js +53 -1
  288. package/utils/object.d.ts +1 -0
  289. package/utils/object.js +6 -0
@@ -0,0 +1,411 @@
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 _xcm = require("@subwallet/extension-base/koni/api/xcm");
12
+ var _utils = require("@subwallet/extension-base/koni/api/yield/helper/utils");
13
+ var _utils2 = require("@subwallet/extension-base/services/chain-service/utils");
14
+ var _types = require("@subwallet/extension-base/types");
15
+ var _bn = _interopRequireDefault(require("bn.js"));
16
+ var _i18next = require("i18next");
17
+ var _util = require("@polkadot/util");
18
+ var _base = _interopRequireDefault(require("./base"));
19
+ // Copyright 2019-2022 @subwallet/extension-base
20
+ // SPDX-License-Identifier: Apache-2.0
21
+
22
+ class BaseSpecialStakingPoolHandler extends _base.default {
23
+ /** Pool's type */
24
+
25
+ /** Allow to create default unstake transaction */
26
+ allowDefaultUnstake = false;
27
+ /** Allow to create fast unstake transaction */
28
+ allowFastUnstake = true;
29
+ get metadataInfo() {
30
+ return {
31
+ altInputAssets: this.altInputAsset,
32
+ derivativeAssets: this.derivativeAssets,
33
+ inputAsset: this.inputAsset,
34
+ rewardAssets: this.rewardAssets,
35
+ feeAssets: this.feeAssets,
36
+ logo: this.logo,
37
+ shortName: this.shortName,
38
+ name: this.name,
39
+ isAvailable: true,
40
+ allowCancelUnstaking: false
41
+ };
42
+ }
43
+ get isPoolSupportAlternativeFee() {
44
+ return this.feeAssets.length > 1;
45
+ }
46
+ get group() {
47
+ const inputAsset = this.state.getAssetBySlug(this.inputAsset);
48
+ const groupSlug = inputAsset.multiChainAsset;
49
+ return groupSlug || this.inputAsset;
50
+ }
51
+
52
+ /* Subscribe pool info */
53
+
54
+ async subscribePoolInfo(callback) {
55
+ let cancel = false;
56
+ const getStatInterval = () => {
57
+ if (!this.isActive) {
58
+ if (!cancel) {
59
+ const rs = {
60
+ ...this.baseInfo,
61
+ type: this.type,
62
+ metadata: {
63
+ ...this.metadataInfo,
64
+ description: this.getDescription()
65
+ }
66
+ };
67
+ callback(rs);
68
+ }
69
+ } else {
70
+ this.getPoolStat().then(rs => {
71
+ if (!cancel) {
72
+ callback(rs);
73
+ }
74
+ }).catch(console.error);
75
+ }
76
+ };
77
+ getStatInterval();
78
+ const interval = setInterval(() => {
79
+ if (cancel) {
80
+ clearInterval(interval);
81
+ } else {
82
+ getStatInterval();
83
+ }
84
+ }, _utils.YIELD_POOL_STAT_REFRESH_INTERVAL);
85
+ return new Promise(resolve => {
86
+ const rs = () => {
87
+ cancel = true;
88
+ clearInterval(interval);
89
+ };
90
+ resolve(rs);
91
+ });
92
+ }
93
+
94
+ /* Subscribe pool info */
95
+
96
+ /* Get pool reward */
97
+
98
+ async getPoolReward() {
99
+ return new Promise(resolve => resolve(_util.noop));
100
+ }
101
+
102
+ /* Get pool reward */
103
+
104
+ /* Get pool targets */
105
+
106
+ async getPoolTargets() {
107
+ return new Promise(resolve => resolve([]));
108
+ }
109
+
110
+ /* Get pool targets */
111
+
112
+ /* Join pool action */
113
+
114
+ /* Generate steps */
115
+
116
+ /**
117
+ * @async
118
+ * @function getXcmStep
119
+ * */
120
+ async getXcmStep(params) {
121
+ const {
122
+ address,
123
+ amount
124
+ } = params;
125
+ const bnAmount = new _bn.default(amount);
126
+ const inputTokenSlug = this.inputAsset; // assume that the pool only has 1 input token, will update later
127
+ const inputTokenInfo = this.state.getAssetBySlug(inputTokenSlug);
128
+ const inputTokenBalance = await this.state.balanceService.getTokenFreeBalance(address, inputTokenInfo.originChain, inputTokenSlug);
129
+ const bnInputTokenBalance = new _bn.default(inputTokenBalance.value);
130
+ if (!bnInputTokenBalance.gte(bnAmount)) {
131
+ if (this.altInputAsset) {
132
+ const altInputTokenSlug = this.altInputAsset;
133
+ const altInputTokenInfo = this.state.getAssetBySlug(altInputTokenSlug);
134
+ const altInputTokenBalance = await this.state.balanceService.getTokenFreeBalance(address, altInputTokenInfo.originChain, altInputTokenSlug);
135
+ const bnAltInputTokenBalance = new _bn.default(altInputTokenBalance.value || '0');
136
+ if (bnAltInputTokenBalance.gt(_util.BN_ZERO)) {
137
+ const step = {
138
+ metadata: {
139
+ sendingValue: bnAmount.toString(),
140
+ originTokenInfo: altInputTokenInfo,
141
+ destinationTokenInfo: inputTokenInfo
142
+ },
143
+ name: 'Transfer DOT from Polkadot',
144
+ type: _types.YieldStepType.XCM
145
+ };
146
+ const xcmOriginSubstrateApi = await this.state.getSubstrateApi(altInputTokenInfo.originChain).isReady;
147
+ const xcmTransfer = await (0, _xcm.createXcmExtrinsic)({
148
+ originTokenInfo: altInputTokenInfo,
149
+ destinationTokenInfo: inputTokenInfo,
150
+ sendingValue: bnAmount.toString(),
151
+ recipient: address,
152
+ chainInfoMap: this.state.getChainInfoMap(),
153
+ substrateApi: xcmOriginSubstrateApi
154
+ });
155
+ const _xcmFeeInfo = await xcmTransfer.paymentInfo(address);
156
+ const xcmFeeInfo = _xcmFeeInfo.toPrimitive();
157
+ // TODO: calculate fee for destination chain
158
+
159
+ const fee = {
160
+ slug: altInputTokenSlug,
161
+ amount: Math.round(xcmFeeInfo.partialFee * 1.2).toString() // TODO
162
+ };
163
+
164
+ return [step, fee];
165
+ }
166
+ }
167
+ }
168
+ return undefined;
169
+ }
170
+ get defaultSubmitStep() {
171
+ return [this.submitJoinStepInfo, {
172
+ slug: this.feeAssets[0],
173
+ amount: '0'
174
+ }];
175
+ }
176
+
177
+ /**
178
+ * @function submitJoinStepInfo
179
+ * @description Base info of submit step
180
+ * @return Fee of the submitting step
181
+ * */
182
+
183
+ async getSubmitStep(params) {
184
+ const fee = await this.getSubmitStepFee(params);
185
+ return [this.submitJoinStepInfo, fee];
186
+ }
187
+
188
+ /* Generate steps */
189
+
190
+ /* Validate join action */
191
+
192
+ async validateTokenApproveStep(params, path) {
193
+ return Promise.resolve([new _TransactionError.TransactionError(_KoniTypes.BasicTxErrorType.UNSUPPORTED)]);
194
+ }
195
+ async validateXcmStep(params, path, bnInputTokenBalance) {
196
+ const processValidation = {
197
+ ok: true,
198
+ status: _types.YieldValidationStatus.OK
199
+ };
200
+ const bnAmount = new _bn.default(params.amount);
201
+ const altInputTokenSlug = this.altInputAsset || '';
202
+ const altInputTokenInfo = this.state.getAssetBySlug(altInputTokenSlug);
203
+ const altInputTokenBalance = await this.state.balanceService.getTokenFreeBalance(params.address, altInputTokenInfo.originChain, altInputTokenSlug);
204
+ const missingAmount = bnAmount.sub(bnInputTokenBalance); // TODO: what if input token is not LOCAL ??
205
+ const xcmFee = new _bn.default(path.totalFee[1].amount || '0');
206
+ const xcmAmount = missingAmount.add(xcmFee);
207
+ const bnAltInputTokenBalance = new _bn.default(altInputTokenBalance.value || '0');
208
+ const altInputTokenMinAmount = new _bn.default(altInputTokenInfo.minAmount || '0');
209
+ if (!bnAltInputTokenBalance.sub(xcmAmount).gte(altInputTokenMinAmount)) {
210
+ processValidation.failedStep = path.steps[1];
211
+ processValidation.ok = false;
212
+ processValidation.status = _types.YieldValidationStatus.NOT_ENOUGH_BALANCE;
213
+ return [new _TransactionError.TransactionError(_types.YieldValidationStatus.NOT_ENOUGH_BALANCE, processValidation.message, processValidation)];
214
+ }
215
+ return [];
216
+ }
217
+ async validateJoinStep(id, params, path, bnInputTokenBalance, isXcmOk) {
218
+ const _poolInfo = await this.getPoolInfo();
219
+ if (!_poolInfo) {
220
+ return [new _TransactionError.TransactionError(_KoniTypes.BasicTxErrorType.INTERNAL_ERROR)];
221
+ }
222
+ const poolInfo = _poolInfo;
223
+ if (!poolInfo.statistic) {
224
+ return [new _TransactionError.TransactionError(_KoniTypes.BasicTxErrorType.INTERNAL_ERROR)];
225
+ }
226
+ const processValidation = {
227
+ ok: true,
228
+ status: _types.YieldValidationStatus.OK
229
+ };
230
+ const feeTokenSlug = path.totalFee[id].slug;
231
+ const feeTokenInfo = this.state.getAssetBySlug(feeTokenSlug);
232
+ const defaultFeeTokenSlug = this.feeAssets[0];
233
+ const bnAmount = new _bn.default(params.amount);
234
+ if (this.feeAssets.length === 1 && feeTokenSlug === defaultFeeTokenSlug) {
235
+ var _path$totalFee$id;
236
+ const bnFeeAmount = new _bn.default(((_path$totalFee$id = path.totalFee[id]) === null || _path$totalFee$id === void 0 ? void 0 : _path$totalFee$id.amount) || '0');
237
+ const feeTokenBalance = await this.state.balanceService.getTokenFreeBalance(params.address, feeTokenInfo.originChain, feeTokenSlug);
238
+ const bnFeeTokenBalance = new _bn.default(feeTokenBalance.value || '0');
239
+ const bnFeeTokenMinAmount = new _bn.default((feeTokenInfo === null || feeTokenInfo === void 0 ? void 0 : feeTokenInfo.minAmount) || '0');
240
+ if (!bnFeeTokenBalance.sub(bnFeeAmount).gte(bnFeeTokenMinAmount)) {
241
+ processValidation.failedStep = path.steps[id];
242
+ processValidation.ok = false;
243
+ processValidation.status = _types.YieldValidationStatus.NOT_ENOUGH_FEE;
244
+ return [new _TransactionError.TransactionError(_types.YieldValidationStatus.NOT_ENOUGH_FEE, processValidation.message, processValidation)];
245
+ }
246
+ }
247
+ if (!bnAmount.gte(new _bn.default(poolInfo.statistic.minJoinPool || '0'))) {
248
+ processValidation.failedStep = path.steps[id];
249
+ processValidation.ok = false;
250
+ processValidation.status = _types.YieldValidationStatus.NOT_ENOUGH_MIN_JOIN_POOL;
251
+ return [new _TransactionError.TransactionError(_types.YieldValidationStatus.NOT_ENOUGH_MIN_JOIN_POOL, processValidation.message, processValidation)];
252
+ }
253
+ if (!isXcmOk && bnAmount.gt(bnInputTokenBalance)) {
254
+ processValidation.failedStep = path.steps[id];
255
+ processValidation.ok = false;
256
+ processValidation.status = _types.YieldValidationStatus.NOT_ENOUGH_BALANCE;
257
+ return [new _TransactionError.TransactionError(_types.YieldValidationStatus.NOT_ENOUGH_BALANCE, processValidation.message, processValidation)];
258
+ }
259
+ return [];
260
+ }
261
+ async validateYieldJoin(params, path) {
262
+ const inputTokenSlug = this.inputAsset;
263
+ const inputTokenInfo = this.state.getAssetBySlug(inputTokenSlug);
264
+ const balanceService = this.state.balanceService;
265
+ const inputTokenBalance = await balanceService.getTokenFreeBalance(params.address, inputTokenInfo.originChain, inputTokenSlug);
266
+ const bnInputTokenBalance = new _bn.default(inputTokenBalance.value || '0');
267
+ let isXcmOk = false;
268
+ for (const step of path.steps) {
269
+ const getErrors = async () => {
270
+ switch (step.type) {
271
+ case _types.YieldStepType.DEFAULT:
272
+ return Promise.resolve([]);
273
+ case _types.YieldStepType.XCM:
274
+ return this.validateXcmStep(params, path, bnInputTokenBalance);
275
+ case _types.YieldStepType.TOKEN_APPROVAL:
276
+ return this.validateTokenApproveStep(params, path);
277
+ default:
278
+ return this.validateJoinStep(step.id, params, path, bnInputTokenBalance, isXcmOk);
279
+ }
280
+ };
281
+ const errors = await getErrors();
282
+ if (errors.length) {
283
+ return errors;
284
+ } else if (step.type === _types.YieldStepType.XCM) {
285
+ isXcmOk = true;
286
+ }
287
+ }
288
+ return [];
289
+ }
290
+
291
+ /* Validate join action */
292
+
293
+ /* Submit join action */
294
+
295
+ async handleTokenApproveStep(data, path) {
296
+ return Promise.reject(new _TransactionError.TransactionError(_KoniTypes.BasicTxErrorType.UNSUPPORTED));
297
+ }
298
+ async handleXcmStep(data, path, xcmFee) {
299
+ const {
300
+ address,
301
+ amount
302
+ } = data;
303
+ const destinationTokenSlug = this.inputAsset;
304
+ const originChainInfo = this.state.getChainInfo(_chainList.COMMON_CHAIN_SLUGS.POLKADOT);
305
+ const originTokenSlug = (0, _utils2._getChainNativeTokenSlug)(originChainInfo);
306
+ const originTokenInfo = this.state.getAssetBySlug(originTokenSlug);
307
+ const destinationTokenInfo = this.state.getAssetBySlug(destinationTokenSlug);
308
+ const substrateApi = this.state.getSubstrateApi(originChainInfo.slug);
309
+ const inputTokenBalance = await this.state.balanceService.getTokenFreeBalance(address, destinationTokenInfo.originChain, destinationTokenSlug);
310
+ const bnInputTokenBalance = new _bn.default(inputTokenBalance.value);
311
+ const bnXcmFee = new _bn.default(xcmFee);
312
+ const bnAmount = new _bn.default(amount);
313
+ const bnTotalAmount = bnAmount.sub(bnInputTokenBalance).add(bnXcmFee);
314
+ const extrinsic = await (0, _xcm.createXcmExtrinsic)({
315
+ chainInfoMap: this.state.getChainInfoMap(),
316
+ destinationTokenInfo,
317
+ originTokenInfo,
318
+ recipient: address,
319
+ sendingValue: bnTotalAmount.toString(),
320
+ substrateApi
321
+ });
322
+ const xcmData = {
323
+ originNetworkKey: originChainInfo.slug,
324
+ destinationNetworkKey: destinationTokenInfo.originChain,
325
+ from: address,
326
+ to: address,
327
+ value: bnTotalAmount.toString(),
328
+ tokenSlug: originTokenSlug,
329
+ showExtraWarning: true
330
+ };
331
+ return {
332
+ txChain: originChainInfo.slug,
333
+ extrinsicType: _KoniTypes.ExtrinsicType.TRANSFER_XCM,
334
+ extrinsic,
335
+ txData: xcmData,
336
+ transferNativeAmount: bnTotalAmount.toString()
337
+ };
338
+ }
339
+ handleYieldJoin(data, path, currentStep) {
340
+ const type = path.steps[currentStep].type;
341
+ switch (type) {
342
+ case _types.YieldStepType.DEFAULT:
343
+ return Promise.reject(new _TransactionError.TransactionError(_KoniTypes.BasicTxErrorType.UNSUPPORTED));
344
+ case _types.YieldStepType.TOKEN_APPROVAL:
345
+ return this.handleTokenApproveStep(data, path);
346
+ case _types.YieldStepType.XCM:
347
+ {
348
+ const xcmFee = path.totalFee[currentStep].amount || '0';
349
+ return this.handleXcmStep(data, path, xcmFee);
350
+ }
351
+ default:
352
+ return this.handleSubmitStep(data, path);
353
+ }
354
+ }
355
+
356
+ /* Submit join action */
357
+
358
+ /* Join pool action */
359
+
360
+ /* Leave pool action */
361
+
362
+ async validateYieldLeave(amount, address, fastLeave, selectedTarget) {
363
+ const poolInfo = await this.getPoolInfo();
364
+ const poolPosition = await this.getPoolPosition(address);
365
+ if (!poolInfo || !poolInfo.statistic || !poolPosition) {
366
+ return [new _TransactionError.TransactionError(_KoniTypes.BasicTxErrorType.INTERNAL_ERROR)];
367
+ }
368
+ if (!this.allowDefaultUnstake && !fastLeave) {
369
+ return [new _TransactionError.TransactionError(_KoniTypes.BasicTxErrorType.INTERNAL_ERROR)];
370
+ }
371
+ if (!this.allowFastUnstake && fastLeave) {
372
+ return [new _TransactionError.TransactionError(_KoniTypes.BasicTxErrorType.INTERNAL_ERROR)];
373
+ }
374
+ const errors = [];
375
+ const bnActiveStake = new _bn.default(poolPosition.activeStake);
376
+ const bnRemainingStake = bnActiveStake.sub(new _bn.default(amount));
377
+ const minStake = new _bn.default(poolInfo.statistic.minJoinPool || '0');
378
+ const maxUnstake = poolInfo.statistic.maxWithdrawalRequestPerFarmer;
379
+ if (!(bnRemainingStake.isZero() || bnRemainingStake.gte(minStake))) {
380
+ errors.push(new _TransactionError.TransactionError(_KoniTypes.StakingTxErrorType.INVALID_ACTIVE_STAKE));
381
+ }
382
+ if (poolPosition.unstakings.length > maxUnstake) {
383
+ errors.push(new _TransactionError.TransactionError(_KoniTypes.StakingTxErrorType.EXCEED_MAX_UNSTAKING, (0, _i18next.t)('You cannot unstake more than {{number}} times', {
384
+ replace: {
385
+ number: maxUnstake
386
+ }
387
+ })));
388
+ }
389
+ return Promise.resolve(errors);
390
+ }
391
+ handleYieldUnstake(amount, address, selectedTarget) {
392
+ return Promise.reject(new _TransactionError.TransactionError(_KoniTypes.BasicTxErrorType.UNSUPPORTED));
393
+ }
394
+
395
+ /* Leave pool action */
396
+
397
+ /* Other action */
398
+
399
+ handleYieldCancelUnstake() {
400
+ return Promise.reject(new _TransactionError.TransactionError(_KoniTypes.BasicTxErrorType.UNSUPPORTED));
401
+ }
402
+ handleYieldClaimReward(address, bondReward) {
403
+ return Promise.reject(new _TransactionError.TransactionError(_KoniTypes.BasicTxErrorType.UNSUPPORTED));
404
+ }
405
+ handleYieldWithdraw(address, unstakingInfo) {
406
+ return Promise.reject(new _TransactionError.TransactionError(_KoniTypes.BasicTxErrorType.UNSUPPORTED));
407
+ }
408
+
409
+ /* Other actions */
410
+ }
411
+ exports.default = BaseSpecialStakingPoolHandler;