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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (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 +14 -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 +6 -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,262 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _KoniTypes = require("@subwallet/extension-base/background/KoniTypes");
8
+ var _constants = require("@subwallet/extension-base/constants");
9
+ var _constants2 = require("@subwallet/extension-base/services/earning-service/constants");
10
+ var _utils = require("@subwallet/extension-base/utils");
11
+ var _util = require("@polkadot/util");
12
+ // Copyright 2019-2022 @subwallet/extension-base
13
+ // SPDX-License-Identifier: Apache-2.0
14
+
15
+ /**
16
+ * @class BasePoolHandler
17
+ * @description Base pool handler
18
+ * */
19
+ class BasePoolHandler {
20
+ /** Koni state */
21
+
22
+ /** Pool's chain */
23
+
24
+ /** Pool's logo */
25
+
26
+ /** Pool's slug */
27
+
28
+ /** Pool's type */
29
+
30
+ /** Pool's name */
31
+
32
+ /** Pool's short name */
33
+
34
+ /** Pool's transaction type */
35
+ transactionChainType = _KoniTypes.ChainType.SUBSTRATE;
36
+
37
+ /** Pool's available method */
38
+
39
+ /**
40
+ * @constructor
41
+ * @param {KoniState} state - Koni state
42
+ * @param {string} chain - Pool's chain
43
+ * */
44
+ constructor(state, chain) {
45
+ this.state = state;
46
+ this.chain = chain;
47
+ this._logo = chain;
48
+ }
49
+ get logo() {
50
+ return this._logo;
51
+ }
52
+ get group() {
53
+ const groupSlug = this.nativeToken.multiChainAsset;
54
+ return groupSlug || this.nativeToken.slug;
55
+ }
56
+ get isActive() {
57
+ return this.state.activeChainSlugs.includes(this.chain);
58
+ }
59
+ get substrateApi() {
60
+ return this.state.getSubstrateApi(this.chain);
61
+ }
62
+ get evmApi() {
63
+ return this.state.getEvmApi(this.chain);
64
+ }
65
+ get chainInfo() {
66
+ return this.state.getChainInfo(this.chain);
67
+ }
68
+ get nativeToken() {
69
+ return this.state.getNativeTokenInfo(this.chain);
70
+ }
71
+ get baseInfo() {
72
+ return {
73
+ group: this.group,
74
+ chain: this.chain,
75
+ slug: this.slug
76
+ };
77
+ }
78
+ getAssetBySlug(slug) {
79
+ return this.state.getAssetBySlug(slug);
80
+ }
81
+ get maintainBalance() {
82
+ const decimals = this.nativeToken.decimals || 0;
83
+ const defaultMaintainBalance = new _util.BN(1).mul(_util.BN_TEN.pow(new _util.BN(decimals)));
84
+ const ed = new _util.BN(this.nativeToken.minAmount || '0');
85
+ const maintainBalance = ed.gte(defaultMaintainBalance) ? new _util.BN(15).mul(ed).div(_util.BN_TEN) : defaultMaintainBalance;
86
+ return maintainBalance.toString();
87
+ }
88
+ get metadataInfo() {
89
+ return {
90
+ name: this.name,
91
+ shortName: this.shortName,
92
+ logo: this.logo,
93
+ inputAsset: this.nativeToken.slug,
94
+ isAvailable: true,
95
+ maintainAsset: this.nativeToken.slug,
96
+ maintainBalance: this.maintainBalance,
97
+ availableMethod: this.availableMethod
98
+ };
99
+ }
100
+
101
+ /** Can mint when haven't enough native token (use input token for fee) */
102
+ get isPoolSupportAlternativeFee() {
103
+ return false;
104
+ }
105
+ async getPoolInfo() {
106
+ return await this.state.earningService.getYieldPool(this.slug);
107
+ }
108
+ async getPoolPosition(address) {
109
+ return await this.state.earningService.getYieldPosition(address, this.slug);
110
+ }
111
+
112
+ /* Subscribe data */
113
+
114
+ /** Subscribe pool info */
115
+
116
+ /* Subscribe data */
117
+
118
+ /* Join action */
119
+
120
+ /* Early validate */
121
+
122
+ async earlyValidate(request) {
123
+ var _poolInfo$statistic, _poolInfo$statistic2, _poolInfo$statistic2$;
124
+ const poolInfo = await this.getPoolInfo();
125
+ if (!poolInfo || !((_poolInfo$statistic = poolInfo.statistic) !== null && _poolInfo$statistic !== void 0 && _poolInfo$statistic.earningThreshold.join)) {
126
+ return {
127
+ passed: false,
128
+ errorMessage: 'There is a problem fetching your data. Check your Internet connection or change the network endpoint and try again.'
129
+ };
130
+ }
131
+ if (request.address === _constants.ALL_ACCOUNT_KEY) {
132
+ return {
133
+ passed: true
134
+ };
135
+ }
136
+ const nativeTokenInfo = this.state.chainService.getNativeTokenInfo(this.chain);
137
+ const nativeTokenBalance = await this.state.balanceService.getTokenFreeBalance(request.address, this.chain);
138
+ const bnNativeTokenBalance = new _util.BN(nativeTokenBalance.value);
139
+ const bnMinBalanceToJoin = new _util.BN(((_poolInfo$statistic2 = poolInfo.statistic) === null || _poolInfo$statistic2 === void 0 ? void 0 : (_poolInfo$statistic2$ = _poolInfo$statistic2.earningThreshold) === null || _poolInfo$statistic2$ === void 0 ? void 0 : _poolInfo$statistic2$.join) || '0').add(new _util.BN(poolInfo.metadata.maintainBalance));
140
+ if (bnNativeTokenBalance.lte(bnMinBalanceToJoin)) {
141
+ const minJoin = (0, _utils.formatNumber)(bnMinBalanceToJoin.toString(), this.nativeToken.decimals || 0);
142
+ const originChain = this.state.getChainInfo(nativeTokenInfo.originChain);
143
+ return {
144
+ passed: false,
145
+ errorMessage: `You need at least ${minJoin} ${nativeTokenInfo.symbol} (${originChain.name}) to start earning`
146
+ };
147
+ }
148
+ return {
149
+ passed: true
150
+ };
151
+ }
152
+
153
+ /* Early validate */
154
+
155
+ /* Generate steps */
156
+
157
+ /**
158
+ * @function firstStepFee
159
+ * */
160
+ get firstStepFee() {
161
+ return {
162
+ slug: ''
163
+ };
164
+ }
165
+
166
+ /**
167
+ * @function defaultSubmitStep
168
+ * @description Default submit step data
169
+ * */
170
+
171
+ /**
172
+ * @async
173
+ * @function getTokenApproveStep
174
+ * @param {OptimalYieldPathParams} params - base param to join pool
175
+ * @description Generate token approve step data
176
+ * */
177
+ async getTokenApproveStep(params) {
178
+ return Promise.resolve(undefined);
179
+ }
180
+
181
+ /**
182
+ * @async
183
+ * @function getXcmStep
184
+ * @param {OptimalYieldPathParams} params - base param to join pool
185
+ * @description Generate token approve step data
186
+ * */
187
+ async getXcmStep(params) {
188
+ return Promise.resolve(undefined);
189
+ }
190
+
191
+ /**
192
+ * @async
193
+ * @function getSubmitStep
194
+ * @param {OptimalYieldPathParams} params - base param to join pool
195
+ * @description Generate token approve step data
196
+ * */
197
+
198
+ /** Generate the optimal steps to join pool */
199
+ async generateOptimalPath(params) {
200
+ const result = {
201
+ totalFee: [this.firstStepFee],
202
+ steps: [_constants2.DEFAULT_YIELD_FIRST_STEP]
203
+ };
204
+ try {
205
+ const stepFunctions = [this.getTokenApproveStep, this.getXcmStep, this.getSubmitStep];
206
+ for (const stepFunction of stepFunctions) {
207
+ const step = await stepFunction.bind(this, params)();
208
+ if (step) {
209
+ const [info, fee] = step;
210
+ result.steps.push({
211
+ id: result.steps.length,
212
+ ...info
213
+ });
214
+ result.totalFee.push(fee);
215
+ }
216
+ }
217
+ return result;
218
+ } catch (e) {
219
+ const errorMessage = e.message;
220
+ if (errorMessage.includes('network')) {
221
+ result.connectionError = errorMessage.split(' ')[0];
222
+ }
223
+
224
+ /* Submit step */
225
+
226
+ const [step, fee] = this.defaultSubmitStep;
227
+ result.steps.push({
228
+ id: result.steps.length,
229
+ ...step
230
+ });
231
+ result.totalFee.push(fee);
232
+
233
+ /* Submit step */
234
+
235
+ return result;
236
+ }
237
+ }
238
+
239
+ /* Generate steps */
240
+
241
+ /* Validate */
242
+
243
+ /** Validate param to join the pool */
244
+
245
+ /** Create `transaction` to leave the pool */
246
+ async handleYieldLeave(fastLeave, amount, address, selectedTarget) {
247
+ if (fastLeave) {
248
+ return this.handleYieldRedeem(amount, address, selectedTarget);
249
+ } else {
250
+ return this.handleYieldUnstake(amount, address, selectedTarget);
251
+ }
252
+ }
253
+
254
+ /* Leave action */
255
+
256
+ /* Other actions */
257
+
258
+ /** Create `transaction` to withdraw unstaked amount */
259
+
260
+ /* Other actions */
261
+ }
262
+ exports.default = BasePoolHandler;
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ var _exportNames = {
8
+ BasePoolHandler: true,
9
+ NominationPoolHandler: true
10
+ };
11
+ Object.defineProperty(exports, "BasePoolHandler", {
12
+ enumerable: true,
13
+ get: function () {
14
+ return _base.default;
15
+ }
16
+ });
17
+ Object.defineProperty(exports, "NominationPoolHandler", {
18
+ enumerable: true,
19
+ get: function () {
20
+ return _nominationPool.default;
21
+ }
22
+ });
23
+ var _base = _interopRequireDefault(require("./base"));
24
+ var _nominationPool = _interopRequireDefault(require("./nomination-pool"));
25
+ var _lending = require("./lending");
26
+ Object.keys(_lending).forEach(function (key) {
27
+ if (key === "default" || key === "__esModule") return;
28
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
29
+ if (key in exports && exports[key] === _lending[key]) return;
30
+ Object.defineProperty(exports, key, {
31
+ enumerable: true,
32
+ get: function () {
33
+ return _lending[key];
34
+ }
35
+ });
36
+ });
37
+ var _liquidStaking = require("./liquid-staking");
38
+ Object.keys(_liquidStaking).forEach(function (key) {
39
+ if (key === "default" || key === "__esModule") return;
40
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
41
+ if (key in exports && exports[key] === _liquidStaking[key]) return;
42
+ Object.defineProperty(exports, key, {
43
+ enumerable: true,
44
+ get: function () {
45
+ return _liquidStaking[key];
46
+ }
47
+ });
48
+ });
49
+ var _nativeStaking = require("./native-staking");
50
+ Object.keys(_nativeStaking).forEach(function (key) {
51
+ if (key === "default" || key === "__esModule") return;
52
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
53
+ if (key in exports && exports[key] === _nativeStaking[key]) return;
54
+ Object.defineProperty(exports, key, {
55
+ enumerable: true,
56
+ get: function () {
57
+ return _nativeStaking[key];
58
+ }
59
+ });
60
+ });
@@ -0,0 +1,81 @@
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 _types = require("@subwallet/extension-base/types");
11
+ var _utils = require("@subwallet/extension-base/utils");
12
+ var _bignumber = _interopRequireDefault(require("bignumber.js"));
13
+ var _i18next = require("i18next");
14
+ var _special = _interopRequireDefault(require("../special"));
15
+ // Copyright 2019-2022 @subwallet/extension-base
16
+ // SPDX-License-Identifier: Apache-2.0
17
+
18
+ class BaseLendingPoolHandler extends _special.default {
19
+ type = _types.YieldPoolType.LENDING;
20
+
21
+ /* Subscribe pool info */
22
+
23
+ /* Subscribe pool info */
24
+
25
+ /* Leave pool action */
26
+
27
+ async validateYieldLeave(amount, address, fastLeave, selectedTarget) {
28
+ const poolInfo = await this.getPoolInfo();
29
+ const poolPosition = await this.getPoolPosition(address);
30
+ if (!poolInfo || !poolInfo.statistic || !poolPosition) {
31
+ return [new _TransactionError.TransactionError(_KoniTypes.BasicTxErrorType.INTERNAL_ERROR)];
32
+ }
33
+ if (!this.availableMethod.defaultUnstake && !fastLeave) {
34
+ return [new _TransactionError.TransactionError(_KoniTypes.BasicTxErrorType.INTERNAL_ERROR)];
35
+ }
36
+ if (!this.availableMethod.fastUnstake && fastLeave) {
37
+ return [new _TransactionError.TransactionError(_KoniTypes.BasicTxErrorType.INTERNAL_ERROR)];
38
+ }
39
+ const errors = [];
40
+ const bnActiveStake = new _bignumber.default(poolPosition.activeStake).multipliedBy(poolInfo.statistic.assetEarning[0].exchangeRate || 1);
41
+ const bnAmount = new _bignumber.default(amount);
42
+ const bnRemainingStake = bnActiveStake.minus(bnAmount);
43
+ const minStake = new _bignumber.default(poolInfo.statistic.earningThreshold.join || '0');
44
+ const minUnstake = new _bignumber.default((fastLeave ? poolInfo.statistic.earningThreshold.fastUnstake : poolInfo.statistic.earningThreshold.defaultUnstake) || '0');
45
+ const maxUnstakeRequest = poolInfo.statistic.maxWithdrawalRequestPerFarmer;
46
+ const derivativeTokenInfo = this.state.getAssetBySlug(this.derivativeAssets[0]);
47
+ if (bnAmount.lte(_utils.BN_ZERO)) {
48
+ return [new _TransactionError.TransactionError(_KoniTypes.BasicTxErrorType.INVALID_PARAMS, (0, _i18next.t)('Amount must be greater than 0'))];
49
+ }
50
+ if (bnAmount.lt(minUnstake)) {
51
+ const minUnstakeStr = (0, _utils.formatNumber)(minUnstake.toString(), derivativeTokenInfo.decimals || 0);
52
+ errors.push(new _TransactionError.TransactionError(_KoniTypes.StakingTxErrorType.NOT_ENOUGH_MIN_UNSTAKE, (0, _i18next.t)('You need to unstake at least {{amount}} {{token}}', {
53
+ replace: {
54
+ amount: minUnstakeStr,
55
+ token: derivativeTokenInfo.symbol
56
+ }
57
+ })));
58
+ }
59
+ if (!fastLeave) {
60
+ if (!(bnRemainingStake.isZero() || bnRemainingStake.gte(minStake))) {
61
+ errors.push(new _TransactionError.TransactionError(_KoniTypes.StakingTxErrorType.INVALID_ACTIVE_STAKE)); // TODO
62
+ }
63
+
64
+ if (poolPosition.unstakings.length > maxUnstakeRequest) {
65
+ errors.push(new _TransactionError.TransactionError(_KoniTypes.StakingTxErrorType.EXCEED_MAX_UNSTAKING, (0, _i18next.t)('You cannot unstake more than {{number}} times', {
66
+ replace: {
67
+ number: maxUnstakeRequest
68
+ }
69
+ })));
70
+ }
71
+ }
72
+ if (bnRemainingStake.lt(0)) {
73
+ errors.push(new _TransactionError.TransactionError(_KoniTypes.StakingTxErrorType.INVALID_ACTIVE_STAKE)); // TODO
74
+ }
75
+
76
+ return Promise.resolve(errors);
77
+ }
78
+
79
+ /* Leave pool action */
80
+ }
81
+ exports.default = BaseLendingPoolHandler;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ Object.defineProperty(exports, "InterlayLendingPoolHandler", {
8
+ enumerable: true,
9
+ get: function () {
10
+ return _interlay.default;
11
+ }
12
+ });
13
+ var _interlay = _interopRequireDefault(require("./interlay"));
@@ -0,0 +1,192 @@
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 _utils = require("@subwallet/extension-base/services/chain-service/utils");
11
+ var _types = require("@subwallet/extension-base/types");
12
+ var _util = require("@polkadot/util");
13
+ var _constants = require("../../constants");
14
+ var _base = _interopRequireDefault(require("./base"));
15
+ // Copyright 2019-2022 @subwallet/extension-base
16
+ // SPDX-License-Identifier: Apache-2.0
17
+
18
+ class InterlayLendingPoolHandler extends _base.default {
19
+ altInputAsset = 'polkadot-NATIVE-DOT';
20
+ derivativeAssets = ['interlay-LOCAL-qDOT'];
21
+ inputAsset = 'interlay-LOCAL-DOT';
22
+ rewardAssets = ['interlay-LOCAL-DOT'];
23
+ feeAssets = ['interlay-NATIVE-INTR', 'interlay-LOCAL-DOT'];
24
+ availableMethod = {
25
+ join: true,
26
+ defaultUnstake: false,
27
+ fastUnstake: true,
28
+ cancelUnstake: false,
29
+ withdraw: false,
30
+ claimReward: false
31
+ };
32
+ rateDecimals = 18;
33
+ constructor(state, chain) {
34
+ super(state, chain);
35
+ const chainInfo = this.chainInfo;
36
+ this.slug = `DOT___lending___${chain}`;
37
+ this.name = `${chainInfo.name} Lending`;
38
+ this.shortName = chainInfo.name.replaceAll(' Relay Chain', '');
39
+ }
40
+ getDescription() {
41
+ return 'Earn rewards by lending DOT';
42
+ }
43
+
44
+ /* Subscribe pool info */
45
+
46
+ async getPoolStat() {
47
+ const substrateApi = await this.substrateApi.isReady;
48
+ const inputTokenSlug = this.inputAsset;
49
+ const inputTokenInfo = this.state.getAssetBySlug(inputTokenSlug);
50
+ const _exchangeRate = await substrateApi.api.query.loans.exchangeRate((0, _utils._getTokenOnChainInfo)(inputTokenInfo));
51
+ const exchangeRate = _exchangeRate.toPrimitive();
52
+ const decimals = 10 ** this.rateDecimals;
53
+ this.updateExchangeRate(exchangeRate);
54
+ return {
55
+ ...this.baseInfo,
56
+ type: this.type,
57
+ metadata: {
58
+ ...this.metadataInfo,
59
+ description: this.getDescription()
60
+ },
61
+ statistic: {
62
+ assetEarning: [{
63
+ slug: this.rewardAssets[0],
64
+ apr: 1.29,
65
+ exchangeRate: exchangeRate / decimals
66
+ }],
67
+ maxCandidatePerFarmer: 1,
68
+ maxWithdrawalRequestPerFarmer: 1,
69
+ earningThreshold: {
70
+ join: '10000000000',
71
+ defaultUnstake: '0',
72
+ fastUnstake: '0'
73
+ },
74
+ totalApr: 1.29,
75
+ tvl: '291890000000000'
76
+ }
77
+ };
78
+ }
79
+
80
+ /* Subscribe pool info */
81
+
82
+ /* Subscribe pool position */
83
+
84
+ async subscribePoolPosition(useAddresses, resultCallback) {
85
+ let cancel = false;
86
+ const substrateApi = this.substrateApi;
87
+ await substrateApi.isReady;
88
+ const derivativeTokenSlug = this.derivativeAssets[0];
89
+ const derivativeTokenInfo = this.state.getAssetBySlug(derivativeTokenSlug);
90
+ const unsub = await substrateApi.api.query.tokens.accounts.multi(useAddresses.map(address => [address, (0, _utils._getTokenOnChainInfo)(derivativeTokenInfo)]), async _balances => {
91
+ if (cancel) {
92
+ unsub();
93
+ return;
94
+ }
95
+ const exchangeRate = await this.getExchangeRate();
96
+ const decimals = _util.BN_TEN.pow(new _util.BN(this.rateDecimals));
97
+ const balances = _balances;
98
+ for (let i = 0; i < balances.length; i++) {
99
+ const balanceItem = balances[i];
100
+ const address = useAddresses[i];
101
+ const bnActiveBalance = balanceItem.free || _util.BN_ZERO;
102
+ const bnTotalBalance = bnActiveBalance.mul(new _util.BN(exchangeRate)).div(decimals);
103
+ const result = {
104
+ ...this.baseInfo,
105
+ type: this.type,
106
+ address,
107
+ balanceToken: this.inputAsset,
108
+ totalStake: bnTotalBalance.toString(),
109
+ activeStake: bnActiveBalance.toString(),
110
+ unstakeBalance: '0',
111
+ status: bnActiveBalance.gt(_util.BN_ZERO) ? _types.EarningStatus.EARNING_REWARD : _types.EarningStatus.NOT_EARNING,
112
+ derivativeToken: derivativeTokenSlug,
113
+ isBondedBefore: bnTotalBalance.gt(_util.BN_ZERO),
114
+ nominations: [],
115
+ unstakings: []
116
+ };
117
+ resultCallback(result);
118
+ }
119
+ });
120
+ return () => {
121
+ cancel = true;
122
+ unsub();
123
+ };
124
+ }
125
+
126
+ /* Subscribe pool position */
127
+
128
+ /* Join pool action */
129
+
130
+ get submitJoinStepInfo() {
131
+ return {
132
+ name: 'Mint qDOT',
133
+ type: _types.YieldStepType.MINT_QDOT
134
+ };
135
+ }
136
+ async getSubmitStepFee(params) {
137
+ const poolOriginSubstrateApi = await this.substrateApi.isReady;
138
+ const inputTokenSlug = this.inputAsset;
139
+ const inputTokenInfo = this.state.getAssetBySlug(inputTokenSlug);
140
+ const defaultFeeTokenSlug = this.feeAssets[0];
141
+ if (new _util.BN(params.amount).gt(_util.BN_ZERO)) {
142
+ const _mintFeeInfo = await poolOriginSubstrateApi.api.tx.loans.mint((0, _utils._getTokenOnChainInfo)(inputTokenInfo), params.amount).paymentInfo(_constants.fakeAddress);
143
+ const mintFeeInfo = _mintFeeInfo.toPrimitive();
144
+ return {
145
+ amount: mintFeeInfo.partialFee.toString(),
146
+ slug: defaultFeeTokenSlug
147
+ };
148
+ } else {
149
+ return {
150
+ amount: '0',
151
+ slug: defaultFeeTokenSlug
152
+ };
153
+ }
154
+ }
155
+ async handleSubmitStep(data, path) {
156
+ const substrateApi = await this.substrateApi.isReady;
157
+ const inputTokenSlug = this.inputAsset;
158
+ const inputTokenInfo = this.state.getAssetBySlug(inputTokenSlug);
159
+ const extrinsic = substrateApi.api.tx.loans.mint((0, _utils._getTokenOnChainInfo)(inputTokenInfo), data.amount);
160
+ return {
161
+ txChain: this.chain,
162
+ extrinsicType: _KoniTypes.ExtrinsicType.MINT_QDOT,
163
+ extrinsic,
164
+ txData: data,
165
+ transferNativeAmount: '0',
166
+ chainType: _KoniTypes.ChainType.SUBSTRATE
167
+ };
168
+ }
169
+
170
+ /* Join pool action */
171
+
172
+ /* Leave pool action */
173
+
174
+ async handleYieldRedeem(amount, address, selectedTarget) {
175
+ const substrateApi = await this.substrateApi.isReady;
176
+ // @ts-ignore
177
+ const inputTokenSlug = this.inputAsset;
178
+ const inputTokenInfo = this.state.getAssetBySlug(inputTokenSlug);
179
+ const yieldPositionInfo = await this.getPoolPosition(address);
180
+ if (!yieldPositionInfo) {
181
+ return Promise.reject(new _TransactionError.TransactionError(_KoniTypes.BasicTxErrorType.INVALID_PARAMS));
182
+ }
183
+ const bnAmount = new _util.BN(amount);
184
+ const bnActiveBalance = new _util.BN(yieldPositionInfo.activeStake);
185
+ const redeemAll = bnAmount.eq(bnActiveBalance);
186
+ const extrinsic = !redeemAll ? substrateApi.api.tx.loans.redeem((0, _utils._getTokenOnChainInfo)(inputTokenInfo), amount) : substrateApi.api.tx.loans.redeemAll((0, _utils._getTokenOnChainInfo)(inputTokenInfo));
187
+ return [_KoniTypes.ExtrinsicType.REDEEM_QDOT, extrinsic];
188
+ }
189
+
190
+ /* Leave pool action */
191
+ }
192
+ exports.default = InterlayLendingPoolHandler;