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