@subwallet/extension-base 1.1.28-0 → 1.1.28-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 (292) hide show
  1. package/background/KoniTypes.d.ts +92 -68
  2. package/background/KoniTypes.js +16 -13
  3. package/background/errors/TransactionError.js +9 -0
  4. package/cjs/background/KoniTypes.js +17 -16
  5. package/cjs/background/errors/TransactionError.js +9 -0
  6. package/cjs/constants/index.js +9 -3
  7. package/cjs/koni/api/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 +17 -15
  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 +2 -0
  25. package/cjs/koni/background/handlers/Extension.js +323 -69
  26. package/cjs/koni/background/handlers/State.js +57 -4
  27. package/cjs/koni/background/handlers/index.js +4 -2
  28. package/cjs/koni/background/subscription.js +89 -19
  29. package/cjs/packageInfo.js +1 -1
  30. package/cjs/services/campaign-service/index.js +9 -6
  31. package/cjs/services/chain-service/constants.js +2 -16
  32. package/cjs/services/chain-service/utils.js +7 -1
  33. package/cjs/services/earning-service/constants/chains.js +29 -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 +202 -0
  37. package/cjs/services/earning-service/handlers/index.js +60 -0
  38. package/cjs/services/earning-service/handlers/lending/base.js +20 -0
  39. package/cjs/services/earning-service/handlers/lending/index.js +13 -0
  40. package/cjs/services/earning-service/handlers/lending/interlay.js +168 -0
  41. package/cjs/services/earning-service/handlers/liquid-staking/acala.js +196 -0
  42. package/cjs/services/earning-service/handlers/liquid-staking/base.js +39 -0
  43. package/cjs/services/earning-service/handlers/liquid-staking/bifrost.js +257 -0
  44. package/cjs/services/earning-service/handlers/liquid-staking/index.js +34 -0
  45. package/cjs/services/earning-service/handlers/liquid-staking/parallel.js +180 -0
  46. package/cjs/services/earning-service/handlers/liquid-staking/stella-swap.js +373 -0
  47. package/cjs/services/earning-service/handlers/native-staking/amplitude.js +359 -0
  48. package/cjs/services/earning-service/handlers/native-staking/astar.js +426 -0
  49. package/cjs/services/earning-service/handlers/native-staking/base-para.js +137 -0
  50. package/cjs/services/earning-service/handlers/native-staking/base.js +109 -0
  51. package/cjs/services/earning-service/handlers/native-staking/index.js +34 -0
  52. package/cjs/services/earning-service/handlers/native-staking/para-chain.js +361 -0
  53. package/cjs/services/earning-service/handlers/native-staking/relay-chain.js +512 -0
  54. package/cjs/services/earning-service/handlers/nomination-pool/index.js +501 -0
  55. package/cjs/services/earning-service/handlers/special.js +387 -0
  56. package/cjs/services/earning-service/service.js +327 -0
  57. package/cjs/services/earning-service/utils/index.js +111 -0
  58. package/cjs/services/event-service/index.js +4 -0
  59. package/cjs/services/keyring-service/index.js +14 -2
  60. package/cjs/services/migration-service/scripts/DeleteEarningData.js +21 -0
  61. package/cjs/services/migration-service/scripts/EnableEarningChains.js +21 -0
  62. package/cjs/services/migration-service/scripts/MigrateEthProvider.js +17 -0
  63. package/cjs/services/migration-service/scripts/MigrateLedgerAccount.js +1 -1
  64. package/cjs/services/migration-service/scripts/MigratePioneerProvider.js +17 -0
  65. package/cjs/services/migration-service/scripts/MigrateProvider.js +29 -0
  66. package/cjs/services/migration-service/scripts/MigrateTransactionHistory.js +1 -1
  67. package/cjs/services/migration-service/scripts/index.js +4 -0
  68. package/cjs/services/mint-campaign-service/campaigns/UnlockDotCampaign.js +149 -0
  69. package/cjs/services/mint-campaign-service/campaigns/index.js +13 -0
  70. package/cjs/services/mint-campaign-service/constants.js +11 -0
  71. package/cjs/services/mint-campaign-service/index.js +18 -0
  72. package/cjs/services/notification-service/NotificationService.js +1 -1
  73. package/cjs/services/storage-service/DatabaseService.js +47 -0
  74. package/cjs/services/storage-service/databases/index.js +4 -0
  75. package/cjs/services/storage-service/db-stores/NominatorMetadata.js +3 -3
  76. package/cjs/services/storage-service/db-stores/YieldPoolStore.js +36 -0
  77. package/cjs/services/storage-service/db-stores/YieldPositionStore.js +65 -0
  78. package/cjs/services/storage-service/index.js +241 -0
  79. package/cjs/services/transaction-service/event-parser/index.js +58 -0
  80. package/cjs/services/transaction-service/helpers/index.js +3 -1
  81. package/cjs/services/transaction-service/index.js +180 -74
  82. package/cjs/services/transaction-service/utils.js +1 -0
  83. package/cjs/types/campaigns/index.js +16 -0
  84. package/cjs/types/campaigns/unlock-dot.js +1 -0
  85. package/cjs/types/index.js +44 -0
  86. package/cjs/types/ordinal.js +1 -0
  87. package/cjs/types/transaction.js +1 -0
  88. package/cjs/types/yield/actions/index.js +27 -0
  89. package/cjs/types/yield/actions/join/index.js +38 -0
  90. package/cjs/types/yield/actions/join/step.js +37 -0
  91. package/cjs/types/yield/actions/join/submit.js +1 -0
  92. package/cjs/types/yield/actions/join/validate.js +16 -0
  93. package/cjs/types/yield/actions/others.js +1 -0
  94. package/cjs/types/yield/index.js +27 -0
  95. package/cjs/types/yield/info/account/index.js +49 -0
  96. package/cjs/types/yield/info/account/info.js +1 -0
  97. package/cjs/types/yield/info/account/reward.js +1 -0
  98. package/cjs/types/yield/info/account/target.js +32 -0
  99. package/cjs/types/yield/info/account/unstake.js +27 -0
  100. package/cjs/types/yield/info/base.js +34 -0
  101. package/cjs/types/yield/info/chain/index.js +27 -0
  102. package/cjs/types/yield/info/chain/info.js +1 -0
  103. package/cjs/types/yield/info/chain/target.js +1 -0
  104. package/cjs/types/yield/info/index.js +49 -0
  105. package/cjs/types/yield/info/pallet.js +15 -0
  106. package/cjs/types.js +1 -0
  107. package/cjs/utils/address.js +34 -0
  108. package/cjs/utils/fetchStaticData.js +2 -1
  109. package/cjs/utils/index.js +89 -1
  110. package/cjs/utils/keyring.js +57 -0
  111. package/cjs/utils/object.js +12 -0
  112. package/constants/index.d.ts +2 -0
  113. package/constants/index.js +2 -0
  114. package/koni/api/nft/config.js +33 -23
  115. package/koni/api/nft/index.js +15 -1
  116. package/koni/api/nft/nft.js +2 -23
  117. package/koni/api/nft/ordinal_nft/constants.d.ts +9 -0
  118. package/koni/api/nft/ordinal_nft/constants.js +12 -0
  119. package/koni/api/nft/ordinal_nft/index.d.ts +8 -0
  120. package/koni/api/nft/ordinal_nft/index.js +114 -0
  121. package/koni/api/nft/ordinal_nft/utils.d.ts +2 -0
  122. package/koni/api/nft/ordinal_nft/utils.js +33 -0
  123. package/koni/api/staking/bonding/amplitude.js +11 -9
  124. package/koni/api/staking/bonding/astar.js +9 -8
  125. package/koni/api/staking/bonding/index.d.ts +1 -1
  126. package/koni/api/staking/bonding/index.js +5 -1
  127. package/koni/api/staking/bonding/paraChain.js +12 -10
  128. package/koni/api/staking/bonding/relayChain.d.ts +2 -2
  129. package/koni/api/staking/bonding/relayChain.js +33 -30
  130. package/koni/api/staking/bonding/utils.d.ts +15 -38
  131. package/koni/api/staking/bonding/utils.js +85 -69
  132. package/koni/api/staking/index.js +2 -1
  133. package/koni/api/staking/paraChain.js +7 -6
  134. package/koni/api/staking/relayChain.js +4 -3
  135. package/koni/api/yield/helper/utils.d.ts +10 -0
  136. package/koni/api/yield/helper/utils.js +32 -0
  137. package/koni/background/cron.js +2 -0
  138. package/koni/background/handlers/Extension.d.ts +14 -1
  139. package/koni/background/handlers/Extension.js +282 -30
  140. package/koni/background/handlers/State.d.ts +18 -2
  141. package/koni/background/handlers/State.js +56 -4
  142. package/koni/background/handlers/index.js +4 -2
  143. package/koni/background/subscription.d.ts +5 -1
  144. package/koni/background/subscription.js +91 -21
  145. package/package.json +311 -8
  146. package/packageInfo.js +1 -1
  147. package/services/campaign-service/index.js +9 -6
  148. package/services/chain-service/constants.d.ts +0 -11
  149. package/services/chain-service/constants.js +1 -14
  150. package/services/chain-service/utils.d.ts +1 -0
  151. package/services/chain-service/utils.js +5 -1
  152. package/services/earning-service/constants/abis/compound_finance_v2_abi.json +1235 -0
  153. package/services/earning-service/constants/abis/st_liquid_token_abi.json +1355 -0
  154. package/services/earning-service/constants/chains.d.ts +14 -0
  155. package/services/earning-service/constants/chains.js +21 -0
  156. package/services/earning-service/constants/index.d.ts +2 -0
  157. package/services/earning-service/constants/index.js +5 -0
  158. package/services/earning-service/constants/step.d.ts +3 -0
  159. package/services/earning-service/constants/step.js +10 -0
  160. package/services/earning-service/handlers/base.d.ts +105 -0
  161. package/services/earning-service/handlers/base.js +195 -0
  162. package/services/earning-service/handlers/index.d.ts +5 -0
  163. package/services/earning-service/handlers/index.js +8 -0
  164. package/services/earning-service/handlers/lending/base.d.ts +6 -0
  165. package/services/earning-service/handlers/lending/base.js +12 -0
  166. package/services/earning-service/handlers/lending/index.d.ts +1 -0
  167. package/services/earning-service/handlers/lending/index.js +4 -0
  168. package/services/earning-service/handlers/lending/interlay.d.ts +22 -0
  169. package/services/earning-service/handlers/lending/interlay.js +160 -0
  170. package/services/earning-service/handlers/liquid-staking/acala.d.ts +27 -0
  171. package/services/earning-service/handlers/liquid-staking/acala.js +188 -0
  172. package/services/earning-service/handlers/liquid-staking/base.d.ts +8 -0
  173. package/services/earning-service/handlers/liquid-staking/base.js +31 -0
  174. package/services/earning-service/handlers/liquid-staking/bifrost.d.ts +44 -0
  175. package/services/earning-service/handlers/liquid-staking/bifrost.js +246 -0
  176. package/services/earning-service/handlers/liquid-staking/index.d.ts +4 -0
  177. package/services/earning-service/handlers/liquid-staking/index.js +7 -0
  178. package/services/earning-service/handlers/liquid-staking/parallel.d.ts +27 -0
  179. package/services/earning-service/handlers/liquid-staking/parallel.js +172 -0
  180. package/services/earning-service/handlers/liquid-staking/stella-swap.d.ts +36 -0
  181. package/services/earning-service/handlers/liquid-staking/stella-swap.js +363 -0
  182. package/services/earning-service/handlers/native-staking/amplitude.d.ts +22 -0
  183. package/services/earning-service/handlers/native-staking/amplitude.js +350 -0
  184. package/services/earning-service/handlers/native-staking/astar.d.ts +18 -0
  185. package/services/earning-service/handlers/native-staking/astar.js +416 -0
  186. package/services/earning-service/handlers/native-staking/base-para.d.ts +11 -0
  187. package/services/earning-service/handlers/native-staking/base-para.js +129 -0
  188. package/services/earning-service/handlers/native-staking/base.d.ts +19 -0
  189. package/services/earning-service/handlers/native-staking/base.js +101 -0
  190. package/services/earning-service/handlers/native-staking/index.d.ts +4 -0
  191. package/services/earning-service/handlers/native-staking/index.js +7 -0
  192. package/services/earning-service/handlers/native-staking/para-chain.d.ts +15 -0
  193. package/services/earning-service/handlers/native-staking/para-chain.js +353 -0
  194. package/services/earning-service/handlers/native-staking/relay-chain.d.ts +21 -0
  195. package/services/earning-service/handlers/native-staking/relay-chain.js +503 -0
  196. package/services/earning-service/handlers/nomination-pool/index.d.ts +33 -0
  197. package/services/earning-service/handlers/nomination-pool/index.js +492 -0
  198. package/services/earning-service/handlers/special.d.ts +56 -0
  199. package/services/earning-service/handlers/special.js +379 -0
  200. package/services/earning-service/service.d.ts +36 -0
  201. package/services/earning-service/service.js +320 -0
  202. package/services/earning-service/utils/index.d.ts +14 -0
  203. package/services/earning-service/utils/index.js +100 -0
  204. package/services/event-service/index.d.ts +1 -0
  205. package/services/event-service/index.js +4 -0
  206. package/services/event-service/types.d.ts +8 -0
  207. package/services/keyring-service/index.d.ts +2 -1
  208. package/services/keyring-service/index.js +14 -2
  209. package/services/migration-service/scripts/DeleteEarningData.d.ts +4 -0
  210. package/services/migration-service/scripts/DeleteEarningData.js +13 -0
  211. package/services/migration-service/scripts/EnableEarningChains.d.ts +4 -0
  212. package/services/migration-service/scripts/EnableEarningChains.js +13 -0
  213. package/services/migration-service/scripts/MigrateLedgerAccount.js +1 -1
  214. package/services/migration-service/scripts/MigrateTransactionHistory.js +1 -1
  215. package/services/migration-service/scripts/index.js +4 -0
  216. package/services/mint-campaign-service/campaigns/UnlockDotCampaign.d.ts +13 -0
  217. package/services/mint-campaign-service/campaigns/UnlockDotCampaign.js +139 -0
  218. package/services/mint-campaign-service/campaigns/index.d.ts +1 -0
  219. package/services/mint-campaign-service/campaigns/index.js +4 -0
  220. package/services/mint-campaign-service/constants.d.ts +1 -0
  221. package/services/mint-campaign-service/constants.js +4 -0
  222. package/services/mint-campaign-service/index.d.ts +7 -0
  223. package/services/mint-campaign-service/index.js +11 -0
  224. package/services/notification-service/NotificationService.js +1 -1
  225. package/services/storage-service/DatabaseService.d.ts +17 -1
  226. package/services/storage-service/DatabaseService.js +47 -0
  227. package/services/storage-service/databases/index.d.ts +3 -1
  228. package/services/storage-service/databases/index.js +4 -0
  229. package/services/storage-service/db-stores/NominatorMetadata.js +3 -3
  230. package/services/storage-service/db-stores/YieldPoolStore.d.ts +10 -0
  231. package/services/storage-service/db-stores/YieldPoolStore.js +28 -0
  232. package/services/storage-service/db-stores/YieldPositionStore.d.ts +9 -0
  233. package/services/storage-service/db-stores/YieldPositionStore.js +57 -0
  234. package/services/subscan-service/index.d.ts +2 -2
  235. package/services/transaction-service/event-parser/index.d.ts +3 -1
  236. package/services/transaction-service/event-parser/index.js +57 -1
  237. package/services/transaction-service/helpers/index.js +3 -1
  238. package/services/transaction-service/index.d.ts +4 -15
  239. package/services/transaction-service/index.js +178 -72
  240. package/services/transaction-service/types.d.ts +2 -0
  241. package/services/transaction-service/utils.js +1 -0
  242. package/types/campaigns/index.d.ts +1 -0
  243. package/types/campaigns/index.js +4 -0
  244. package/types/campaigns/unlock-dot.d.ts +71 -0
  245. package/types/campaigns/unlock-dot.js +1 -0
  246. package/types/index.d.ts +5 -0
  247. package/types/index.js +5 -1
  248. package/types/ordinal.d.ts +69 -0
  249. package/types/ordinal.js +1 -0
  250. package/types/transaction.d.ts +3 -0
  251. package/types/transaction.js +1 -0
  252. package/types/yield/actions/index.d.ts +2 -0
  253. package/types/yield/actions/index.js +5 -0
  254. package/types/yield/actions/join/index.d.ts +3 -0
  255. package/types/yield/actions/join/index.js +6 -0
  256. package/types/yield/actions/join/step.d.ts +75 -0
  257. package/types/yield/actions/join/step.js +34 -0
  258. package/types/yield/actions/join/submit.d.ts +53 -0
  259. package/types/yield/actions/join/submit.js +1 -0
  260. package/types/yield/actions/join/validate.d.ts +18 -0
  261. package/types/yield/actions/join/validate.js +10 -0
  262. package/types/yield/actions/others.d.ts +60 -0
  263. package/types/yield/actions/others.js +1 -0
  264. package/types/yield/index.d.ts +2 -0
  265. package/types/yield/index.js +5 -0
  266. package/types/yield/info/account/index.d.ts +4 -0
  267. package/types/yield/info/account/index.js +7 -0
  268. package/types/yield/info/account/info.d.ts +112 -0
  269. package/types/yield/info/account/info.js +1 -0
  270. package/types/yield/info/account/reward.d.ts +41 -0
  271. package/types/yield/info/account/reward.js +1 -0
  272. package/types/yield/info/account/target.d.ts +43 -0
  273. package/types/yield/info/account/target.js +27 -0
  274. package/types/yield/info/account/unstake.d.ts +31 -0
  275. package/types/yield/info/account/unstake.js +22 -0
  276. package/types/yield/info/base.d.ts +28 -0
  277. package/types/yield/info/base.js +28 -0
  278. package/types/yield/info/chain/index.d.ts +2 -0
  279. package/types/yield/info/chain/index.js +5 -0
  280. package/types/yield/info/chain/info.d.ts +190 -0
  281. package/types/yield/info/chain/info.js +1 -0
  282. package/types/yield/info/chain/target.d.ts +33 -0
  283. package/types/yield/info/chain/target.js +1 -0
  284. package/types/yield/info/index.d.ts +4 -0
  285. package/types/yield/info/index.js +7 -0
  286. package/types/yield/info/pallet.d.ts +143 -0
  287. package/types/yield/info/pallet.js +9 -0
  288. package/utils/fetchStaticData.js +2 -1
  289. package/utils/index.d.ts +5 -0
  290. package/utils/index.js +53 -1
  291. package/utils/object.d.ts +1 -0
  292. package/utils/object.js +6 -0
@@ -0,0 +1,257 @@
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 _KoniTypes = require("@subwallet/extension-base/background/KoniTypes");
9
+ var _constants = require("@subwallet/extension-base/services/chain-service/constants");
10
+ var _utils = require("@subwallet/extension-base/services/chain-service/utils");
11
+ var _constants2 = require("@subwallet/extension-base/services/earning-service/constants");
12
+ var _types = require("@subwallet/extension-base/types");
13
+ var _utils2 = require("@subwallet/extension-base/utils");
14
+ var _crossFetch = _interopRequireDefault(require("cross-fetch"));
15
+ var _util = require("@polkadot/util");
16
+ var _base = _interopRequireDefault(require("./base"));
17
+ // Copyright 2019-2022 @subwallet/extension-base
18
+ // SPDX-License-Identifier: Apache-2.0
19
+
20
+ const STATS_URL = 'https://api.bifrost.app/api/site';
21
+ const BIFROST_GRAPHQL_ENDPOINT = 'https://bifrost-subsql.liebi.com/v1/graphql';
22
+ const BIFROST_EXCHANGE_RATE_REQUEST = 'query MyQuery{slp_polkadot_ratio(limit:1 where:{key:{_eq:"0"}} order_by:{timestamp:desc_nulls_first}){ratio key timestamp total_issuance token_pool}}';
23
+ class BifrostLiquidStakingPoolHandler extends _base.default {
24
+ altInputAsset = 'polkadot-NATIVE-DOT';
25
+ derivativeAssets = ['bifrost_dot-LOCAL-vDOT'];
26
+ inputAsset = 'bifrost_dot-LOCAL-DOT';
27
+ rewardAssets = ['bifrost_dot-LOCAL-DOT'];
28
+ feeAssets = ['bifrost_dot-NATIVE-BNC', 'bifrost_dot-LOCAL-DOT'];
29
+ /** @inner */
30
+ minAmountPercent = 0.99;
31
+ constructor(state, chain) {
32
+ super(state, chain);
33
+ const chainInfo = this.chainInfo;
34
+ this.slug = `DOT___liquid_staking___${chain}`;
35
+ this.name = `${chainInfo.name} Liquid Staking`;
36
+ this.description = 'Stake DOT to earn yield on vDOT';
37
+ this.shortName = chainInfo.name.replaceAll(' Relay Chain', '');
38
+ }
39
+
40
+ /* Subscribe pool info */
41
+
42
+ async getPoolStat() {
43
+ const stakingMetaPromise = new Promise(function (resolve) {
44
+ (0, _crossFetch.default)(STATS_URL, {
45
+ method: 'GET'
46
+ }).then(res => {
47
+ resolve(res.json());
48
+ }).catch(console.error);
49
+ });
50
+ const exchangeRatePromise = new Promise(function (resolve) {
51
+ (0, _crossFetch.default)(BIFROST_GRAPHQL_ENDPOINT, {
52
+ method: 'POST',
53
+ headers: {
54
+ 'Content-Type': 'application/json'
55
+ },
56
+ body: JSON.stringify({
57
+ query: BIFROST_EXCHANGE_RATE_REQUEST
58
+ })
59
+ }).then(resp => {
60
+ resolve(resp.json());
61
+ }).catch(console.error);
62
+ });
63
+ const [_stakingMeta, _exchangeRate] = await Promise.all([stakingMetaPromise, exchangeRatePromise]);
64
+ const stakingMeta = _stakingMeta;
65
+ const exchangeRate = _exchangeRate;
66
+ const vDOTStats = stakingMeta.vDOT;
67
+ const assetInfo = this.state.getAssetBySlug(this.inputAsset);
68
+ const assetDecimals = 10 ** (0, _utils._getAssetDecimals)(assetInfo);
69
+ return {
70
+ ...this.defaultInfo,
71
+ description: this.description,
72
+ type: this.type,
73
+ metadata: {
74
+ ...this.baseMetadata,
75
+ isAvailable: true,
76
+ allowCancelUnstaking: false,
77
+ assetEarning: [{
78
+ slug: this.rewardAssets[0],
79
+ apy: parseFloat(vDOTStats.apyBase),
80
+ exchangeRate: parseFloat(exchangeRate.data.slp_polkadot_ratio[0].ratio)
81
+ }],
82
+ maxCandidatePerFarmer: 1,
83
+ maxWithdrawalRequestPerFarmer: 1,
84
+ minJoinPool: '5000000000',
85
+ minWithdrawal: '4000000000',
86
+ totalApy: parseFloat(vDOTStats.apyBase),
87
+ tvl: (vDOTStats.tvm * assetDecimals).toString()
88
+ }
89
+ };
90
+ }
91
+
92
+ /* Subscribe pool info */
93
+
94
+ /* Subscribe pool position */
95
+
96
+ async subscribePoolPosition(useAddresses, resultCallback) {
97
+ let cancel = false;
98
+ const substrateApi = this.substrateApi;
99
+ await substrateApi.isReady;
100
+
101
+ // @ts-ignore
102
+ const derivativeTokenSlug = this.derivativeAssets[0];
103
+ const derivativeTokenInfo = this.state.getAssetBySlug(derivativeTokenSlug);
104
+ const inputTokenSlug = this.inputAsset;
105
+ const inputTokenInfo = this.state.getAssetBySlug(inputTokenSlug);
106
+ const unsub = await substrateApi.api.query.tokens.accounts.multi(useAddresses.map(address => [address, (0, _utils._getTokenOnChainInfo)(derivativeTokenInfo)]), async _balance => {
107
+ if (cancel) {
108
+ unsub();
109
+ return;
110
+ }
111
+ const balances = _balance;
112
+ const [_unlockLedgerList, _currentRelayEra] = await Promise.all([substrateApi.api.query.vtokenMinting.userUnlockLedger.multi(useAddresses.map(address => [address, (0, _utils._getTokenOnChainInfo)(inputTokenInfo)])), substrateApi.api.query.vtokenMinting.ongoingTimeUnit((0, _utils._getTokenOnChainInfo)(inputTokenInfo))]);
113
+ const currentRelayEraObj = _currentRelayEra.toPrimitive();
114
+ const currentRelayEra = currentRelayEraObj.Era;
115
+ const unlockLedgerList = [];
116
+ const activeBalanceMap = {};
117
+ for (let i = 0; i < balances.length; i++) {
118
+ const balanceItem = balances[i];
119
+ const address = useAddresses[i];
120
+ const formattedAddress = (0, _utils2.reformatAddress)(address);
121
+ activeBalanceMap[formattedAddress] = balanceItem.free || _util.BN_ZERO;
122
+ const _unlockLedger = _unlockLedgerList[i];
123
+ const unlockLedger = _unlockLedger.toPrimitive();
124
+ if (unlockLedger) {
125
+ // @ts-ignore
126
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
127
+ const unstakingLedgerIds = unlockLedger[1];
128
+ unstakingLedgerIds.forEach(ledgerId => {
129
+ unlockLedgerList.push({
130
+ address: formattedAddress,
131
+ ledgerId
132
+ });
133
+ });
134
+ }
135
+
136
+ // const bnTotalBalance = bnActiveBalance.add(bnUnstakingBalance);
137
+ }
138
+
139
+ const unlockingMap = {};
140
+ const _unlockInfoList = await substrateApi.api.query.vtokenMinting.tokenUnlockLedger.multi(unlockLedgerList.map(_ref => {
141
+ let {
142
+ ledgerId
143
+ } = _ref;
144
+ return [(0, _utils._getTokenOnChainInfo)(inputTokenInfo), ledgerId];
145
+ }));
146
+ for (let i = 0; i < _unlockInfoList.length; i++) {
147
+ const unlockInfo = _unlockInfoList[i].toPrimitive();
148
+ const owner = (0, _utils2.reformatAddress)(unlockInfo[0]);
149
+ const amount = unlockInfo[1].toString();
150
+ // @ts-ignore
151
+ const withdrawalEra = unlockInfo[2].era;
152
+ if (owner in unlockingMap) {
153
+ unlockingMap[owner].push({
154
+ balance: amount,
155
+ era: withdrawalEra
156
+ });
157
+ } else {
158
+ unlockingMap[owner] = [{
159
+ balance: amount,
160
+ era: withdrawalEra
161
+ }];
162
+ }
163
+ }
164
+ const unstakingList = [];
165
+ useAddresses.forEach(address => {
166
+ const formattedAddress = (0, _utils2.reformatAddress)(address);
167
+ const bnActiveBalance = activeBalanceMap[formattedAddress];
168
+ const unlockings = unlockingMap[formattedAddress];
169
+ let unlockBalance = _util.BN_ZERO;
170
+ if (unlockings) {
171
+ unlockings.forEach(unlocking => {
172
+ const isClaimable = unlocking.era - currentRelayEra < 0;
173
+ const remainingEra = unlocking.era - currentRelayEra;
174
+ const waitingTime = remainingEra * _constants._STAKING_ERA_LENGTH_MAP[this.chain];
175
+ unlockBalance = unlockBalance.add(new _util.BN(unlocking.balance));
176
+ unstakingList.push({
177
+ chain: this.chain,
178
+ status: isClaimable ? _types.UnstakingStatus.CLAIMABLE : _types.UnstakingStatus.UNLOCKING,
179
+ claimable: unlocking.balance,
180
+ waitingTime: waitingTime
181
+ });
182
+ });
183
+ }
184
+ const totalBalance = bnActiveBalance.add(unlockBalance);
185
+ const result = {
186
+ ...this.defaultInfo,
187
+ type: this.type,
188
+ address,
189
+ balanceToken: this.inputAsset,
190
+ derivativeToken: derivativeTokenSlug,
191
+ totalStake: totalBalance.toString(),
192
+ activeStake: bnActiveBalance.toString(),
193
+ unstakeBalance: unlockBalance.toString(),
194
+ status: bnActiveBalance.eq(_util.BN_ZERO) ? _types.EarningStatus.NOT_EARNING : _types.EarningStatus.EARNING_REWARD,
195
+ isBondedBefore: totalBalance.gt(_util.BN_ZERO),
196
+ nominations: [],
197
+ unstakings: unstakingList
198
+ };
199
+ resultCallback(result);
200
+ });
201
+ });
202
+ return () => {
203
+ cancel = true;
204
+ unsub();
205
+ };
206
+ }
207
+
208
+ /* Subscribe pool position */
209
+
210
+ /* Join pool action */
211
+
212
+ get submitJoinStepInfo() {
213
+ return {
214
+ name: 'Mint vDOT',
215
+ type: _types.YieldStepType.MINT_VDOT
216
+ };
217
+ }
218
+ async getSubmitStepFee(params) {
219
+ const poolOriginSubstrateApi = await this.substrateApi.isReady;
220
+ const inputTokenSlug = this.inputAsset;
221
+ const inputTokenInfo = this.state.getAssetBySlug(inputTokenSlug);
222
+ const defaultFeeTokenSlug = this.feeAssets[0];
223
+ const _mintFeeInfo = await poolOriginSubstrateApi.api.tx.vtokenMinting.mint((0, _utils._getTokenOnChainInfo)(inputTokenInfo), params.amount, null).paymentInfo(_constants2.fakeAddress);
224
+ const mintFeeInfo = _mintFeeInfo.toPrimitive();
225
+ return {
226
+ amount: mintFeeInfo.partialFee.toString(),
227
+ slug: defaultFeeTokenSlug
228
+ };
229
+ }
230
+ async handleSubmitStep(data, path) {
231
+ const substrateApi = await this.substrateApi.isReady;
232
+ const inputTokenSlug = this.inputAsset;
233
+ const inputTokenInfo = this.state.getAssetBySlug(inputTokenSlug);
234
+ const extrinsic = substrateApi.api.tx.vtokenMinting.mint((0, _utils._getTokenOnChainInfo)(inputTokenInfo), data.amount, undefined);
235
+ return {
236
+ txChain: this.chain,
237
+ extrinsicType: _KoniTypes.ExtrinsicType.MINT_VDOT,
238
+ extrinsic,
239
+ txData: data,
240
+ transferNativeAmount: '0'
241
+ };
242
+ }
243
+
244
+ /* Join pool action */
245
+
246
+ /* Leave pool action */
247
+
248
+ async handleYieldRedeem(amount, address, selectedTarget) {
249
+ const substrateApi = await this.substrateApi.isReady;
250
+ const weightedMinAmount = await this.createParamToRedeem(amount, address);
251
+ const extrinsic = substrateApi.api.tx.stablePool.swap(0, 1, 0, amount, weightedMinAmount);
252
+ return [_KoniTypes.ExtrinsicType.REDEEM_VDOT, extrinsic];
253
+ }
254
+
255
+ /* Leave pool action */
256
+ }
257
+ exports.default = BifrostLiquidStakingPoolHandler;
@@ -0,0 +1,34 @@
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, "AcalaLiquidStakingPoolHandler", {
8
+ enumerable: true,
9
+ get: function () {
10
+ return _acala.default;
11
+ }
12
+ });
13
+ Object.defineProperty(exports, "BifrostLiquidStakingPoolHandler", {
14
+ enumerable: true,
15
+ get: function () {
16
+ return _bifrost.default;
17
+ }
18
+ });
19
+ Object.defineProperty(exports, "ParallelLiquidStakingPoolHandler", {
20
+ enumerable: true,
21
+ get: function () {
22
+ return _parallel.default;
23
+ }
24
+ });
25
+ Object.defineProperty(exports, "StellaSwapLiquidStakingPoolHandler", {
26
+ enumerable: true,
27
+ get: function () {
28
+ return _stellaSwap.default;
29
+ }
30
+ });
31
+ var _acala = _interopRequireDefault(require("./acala"));
32
+ var _bifrost = _interopRequireDefault(require("./bifrost"));
33
+ var _parallel = _interopRequireDefault(require("./parallel"));
34
+ var _stellaSwap = _interopRequireDefault(require("./stella-swap"));
@@ -0,0 +1,180 @@
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 _KoniTypes = require("@subwallet/extension-base/background/KoniTypes");
9
+ var _utils = require("@subwallet/extension-base/services/chain-service/utils");
10
+ var _constants = require("@subwallet/extension-base/services/earning-service/constants");
11
+ var _types = require("@subwallet/extension-base/types");
12
+ var _util = require("@polkadot/util");
13
+ var _base = _interopRequireDefault(require("./base"));
14
+ // Copyright 2019-2022 @subwallet/extension-base
15
+ // SPDX-License-Identifier: Apache-2.0
16
+
17
+ class ParallelLiquidStakingPoolHandler extends _base.default {
18
+ altInputAsset = 'polkadot-NATIVE-DOT';
19
+ derivativeAssets = ['parallel-LOCAL-sDOT'];
20
+ inputAsset = 'parallel-LOCAL-DOT';
21
+ rewardAssets = ['parallel-LOCAL-DOT'];
22
+ feeAssets = ['parallel-NATIVE-PARA'];
23
+ /** @inner */
24
+ minAmountPercent = 0.97;
25
+ /** @inner */
26
+ allowDefaultUnstake = true;
27
+ constructor(state, chain) {
28
+ super(state, chain);
29
+ const chainInfo = this.chainInfo;
30
+ this.slug = `DOT___liquid_staking___${chain}`;
31
+ this.name = `${chainInfo.name} Liquid Staking`;
32
+ this.shortName = chainInfo.name.replaceAll(' Relay Chain', '');
33
+ this.description = 'Stake DOT to earn yield on sDOT';
34
+ }
35
+
36
+ /* Subscribe pool info */
37
+
38
+ async getPoolStat() {
39
+ const substrateApi = await this.substrateApi.isReady;
40
+ const [_exchangeRate, _currentBlockHeader, _currentTimestamp, _stakingLedgers] = await Promise.all([substrateApi.api.query.liquidStaking.exchangeRate(), substrateApi.api.rpc.chain.getHeader(), substrateApi.api.query.timestamp.now(), substrateApi.api.query.liquidStaking.stakingLedgers.entries()]);
41
+ let tvl = _util.BN_ZERO;
42
+ for (const _stakingLedger of _stakingLedgers) {
43
+ const _ledger = _stakingLedger[1];
44
+ const ledger = _ledger.toPrimitive();
45
+ tvl = tvl.add(new _util.BN(ledger.total.toString()));
46
+ }
47
+ const exchangeRate = _exchangeRate.toPrimitive();
48
+ const currentBlockHeader = _currentBlockHeader.toPrimitive();
49
+ const currentTimestamp = _currentTimestamp.toPrimitive();
50
+ const beginBlock = currentBlockHeader.number - 24 * 60 * 60 / 6 * 14;
51
+ const _beginBlockHash = await substrateApi.api.rpc.chain.getBlockHash(beginBlock);
52
+ const beginBlockHash = _beginBlockHash.toString();
53
+ const [_beginTimestamp, _beginExchangeRate] = await Promise.all([substrateApi.api.query.timestamp.now.at(beginBlockHash), substrateApi.api.query.liquidStaking.exchangeRate.at(beginBlockHash)]);
54
+ const beginTimestamp = _beginTimestamp.toPrimitive();
55
+ const beginExchangeRate = _beginExchangeRate.toPrimitive();
56
+ const decimals = 10 ** 18;
57
+ const apy = (exchangeRate / beginExchangeRate) ** (365 * 24 * 60 * 60000 / (currentTimestamp - beginTimestamp)) - 1;
58
+ return {
59
+ ...this.defaultInfo,
60
+ description: this.description,
61
+ type: this.type,
62
+ metadata: {
63
+ ...this.baseMetadata,
64
+ isAvailable: true,
65
+ allowCancelUnstaking: false,
66
+ assetEarning: [{
67
+ slug: this.rewardAssets[0],
68
+ apy: apy * 100,
69
+ exchangeRate: exchangeRate / decimals
70
+ }],
71
+ maxCandidatePerFarmer: 1,
72
+ maxWithdrawalRequestPerFarmer: 1,
73
+ minJoinPool: '10000000000',
74
+ minWithdrawal: '5000000000',
75
+ totalApy: apy * 100,
76
+ tvl: tvl.toString()
77
+ }
78
+ };
79
+ }
80
+
81
+ /* Subscribe pool info */
82
+
83
+ /* Subscribe pool position */
84
+
85
+ async subscribePoolPosition(useAddresses, resultCallback) {
86
+ let cancel = false;
87
+ const substrateApi = this.substrateApi;
88
+ await substrateApi.isReady;
89
+ const derivativeTokenSlug = this.derivativeAssets[0];
90
+ const derivativeTokenInfo = this.state.getAssetBySlug(derivativeTokenSlug);
91
+ const unsub = await substrateApi.api.query.assets.account.multi(useAddresses.map(address => [(0, _utils._getTokenOnChainAssetId)(derivativeTokenInfo), address]), balances => {
92
+ if (cancel) {
93
+ unsub();
94
+ return;
95
+ }
96
+ for (let i = 0; i < balances.length; i++) {
97
+ const b = balances[i];
98
+ const address = useAddresses[i];
99
+ // @ts-ignore
100
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-assignment
101
+ const bdata = b === null || b === void 0 ? void 0 : b.toHuman();
102
+
103
+ // @ts-ignore
104
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-argument
105
+ const bnTotalBalance = bdata && bdata.balance ? new _util.BN(String(bdata === null || bdata === void 0 ? void 0 : bdata.balance).replaceAll(',', '') || '0') : _util.BN_ZERO;
106
+ const totalBalance = bnTotalBalance.toString();
107
+ const result = {
108
+ ...this.defaultInfo,
109
+ type: this.type,
110
+ address,
111
+ balanceToken: this.inputAsset,
112
+ totalStake: totalBalance,
113
+ activeStake: totalBalance,
114
+ unstakeBalance: '0',
115
+ status: _types.EarningStatus.EARNING_REWARD,
116
+ derivativeToken: derivativeTokenSlug,
117
+ isBondedBefore: bnTotalBalance.gt(_util.BN_ZERO),
118
+ nominations: [],
119
+ unstakings: []
120
+ };
121
+ resultCallback(result);
122
+ }
123
+ });
124
+ return () => {
125
+ cancel = true;
126
+ unsub();
127
+ };
128
+ }
129
+
130
+ /* Subscribe pool position */
131
+
132
+ /* Join pool action */
133
+
134
+ get submitJoinStepInfo() {
135
+ return {
136
+ name: 'Mint sDOT',
137
+ type: _types.YieldStepType.MINT_SDOT
138
+ };
139
+ }
140
+ async getSubmitStepFee(params) {
141
+ const poolOriginSubstrateApi = await this.substrateApi.isReady;
142
+ const defaultFeeTokenSlug = this.feeAssets[0];
143
+ const _mintFeeInfo = await poolOriginSubstrateApi.api.tx.liquidStaking.stake(params.amount).paymentInfo(_constants.fakeAddress);
144
+ const mintFeeInfo = _mintFeeInfo.toPrimitive();
145
+ return {
146
+ amount: mintFeeInfo.partialFee.toString(),
147
+ slug: defaultFeeTokenSlug
148
+ };
149
+ }
150
+ async handleSubmitStep(data, path) {
151
+ const substrateApi = await this.substrateApi.isReady;
152
+ const extrinsic = substrateApi.api.tx.liquidStaking.stake(data.amount);
153
+ return {
154
+ txChain: this.chain,
155
+ extrinsicType: _KoniTypes.ExtrinsicType.MINT_SDOT,
156
+ extrinsic,
157
+ txData: data,
158
+ transferNativeAmount: '0'
159
+ };
160
+ }
161
+
162
+ /* Join pool action */
163
+
164
+ /* Leave pool action */
165
+
166
+ async handleYieldRedeem(amount, address, selectedTarget) {
167
+ const substrateApi = await this.substrateApi.isReady;
168
+ const weightedMinAmount = await this.createParamToRedeem(amount, address);
169
+ const extrinsic = substrateApi.api.tx.ammRoute.swapExactTokensForTokens(['1001', '101'], amount, weightedMinAmount);
170
+ return [_KoniTypes.ExtrinsicType.REDEEM_SDOT, extrinsic];
171
+ }
172
+ async handleYieldUnstake(amount, address, selectedTarget) {
173
+ const chainApi = await this.substrateApi.isReady;
174
+ const extrinsic = chainApi.api.tx.liquidStaking.unstake(amount, 'RelayChain');
175
+ return [_KoniTypes.ExtrinsicType.UNSTAKE_SDOT, extrinsic];
176
+ }
177
+
178
+ /* Leave pool action */
179
+ }
180
+ exports.default = ParallelLiquidStakingPoolHandler;