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