@subwallet/extension-base 1.1.35-0 → 1.1.35-beta.1

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