@subwallet/extension-base 1.1.29-0 → 1.1.29-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 (289) hide show
  1. package/background/KoniTypes.d.ts +94 -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/nft/config.js +33 -23
  8. package/cjs/koni/api/nft/index.js +14 -0
  9. package/cjs/koni/api/nft/nft.js +1 -22
  10. package/cjs/koni/api/nft/ordinal_nft/constants.js +21 -0
  11. package/cjs/koni/api/nft/ordinal_nft/index.js +121 -0
  12. package/cjs/koni/api/nft/ordinal_nft/utils.js +41 -0
  13. package/cjs/koni/api/staking/bonding/amplitude.js +17 -15
  14. package/cjs/koni/api/staking/bonding/astar.js +11 -10
  15. package/cjs/koni/api/staking/bonding/index.js +4 -1
  16. package/cjs/koni/api/staking/bonding/paraChain.js +25 -23
  17. package/cjs/koni/api/staking/bonding/relayChain.js +48 -45
  18. package/cjs/koni/api/staking/bonding/utils.js +104 -86
  19. package/cjs/koni/api/staking/index.js +6 -5
  20. package/cjs/koni/api/staking/paraChain.js +6 -5
  21. package/cjs/koni/api/staking/relayChain.js +3 -2
  22. package/cjs/koni/api/yield/helper/utils.js +46 -0
  23. package/cjs/koni/background/cron.js +2 -0
  24. package/cjs/koni/background/handlers/Extension.js +347 -69
  25. package/cjs/koni/background/handlers/State.js +51 -3
  26. package/cjs/koni/background/handlers/index.js +4 -2
  27. package/cjs/koni/background/subscription.js +88 -18
  28. package/cjs/services/campaign-service/index.js +9 -6
  29. package/cjs/services/chain-service/constants.js +2 -16
  30. package/cjs/services/chain-service/utils.js +7 -1
  31. package/cjs/services/earning-service/constants/chains.js +29 -0
  32. package/cjs/services/earning-service/constants/index.js +27 -0
  33. package/cjs/services/earning-service/constants/step.js +18 -0
  34. package/cjs/services/earning-service/handlers/base.js +230 -0
  35. package/cjs/services/earning-service/handlers/index.js +60 -0
  36. package/cjs/services/earning-service/handlers/lending/base.js +20 -0
  37. package/cjs/services/earning-service/handlers/lending/index.js +13 -0
  38. package/cjs/services/earning-service/handlers/lending/interlay.js +176 -0
  39. package/cjs/services/earning-service/handlers/liquid-staking/acala.js +206 -0
  40. package/cjs/services/earning-service/handlers/liquid-staking/base.js +43 -0
  41. package/cjs/services/earning-service/handlers/liquid-staking/bifrost.js +267 -0
  42. package/cjs/services/earning-service/handlers/liquid-staking/index.js +34 -0
  43. package/cjs/services/earning-service/handlers/liquid-staking/parallel.js +190 -0
  44. package/cjs/services/earning-service/handlers/liquid-staking/stella-swap.js +382 -0
  45. package/cjs/services/earning-service/handlers/native-staking/amplitude.js +380 -0
  46. package/cjs/services/earning-service/handlers/native-staking/astar.js +454 -0
  47. package/cjs/services/earning-service/handlers/native-staking/base-para.js +137 -0
  48. package/cjs/services/earning-service/handlers/native-staking/base.js +119 -0
  49. package/cjs/services/earning-service/handlers/native-staking/index.js +34 -0
  50. package/cjs/services/earning-service/handlers/native-staking/para-chain.js +381 -0
  51. package/cjs/services/earning-service/handlers/native-staking/relay-chain.js +540 -0
  52. package/cjs/services/earning-service/handlers/nomination-pool/index.js +528 -0
  53. package/cjs/services/earning-service/handlers/special.js +412 -0
  54. package/cjs/services/earning-service/service.js +351 -0
  55. package/cjs/services/earning-service/utils/index.js +128 -0
  56. package/cjs/services/event-service/index.js +4 -0
  57. package/cjs/services/keyring-service/index.js +14 -2
  58. package/cjs/services/migration-service/scripts/DeleteEarningData.js +21 -0
  59. package/cjs/services/migration-service/scripts/EnableEarningChains.js +21 -0
  60. package/cjs/services/migration-service/scripts/MigrateLedgerAccount.js +1 -1
  61. package/cjs/services/migration-service/scripts/MigrateTransactionHistory.js +1 -1
  62. package/cjs/services/migration-service/scripts/databases/MigrateEarningHistory.js +21 -0
  63. package/cjs/services/migration-service/scripts/databases/MigrateEarningVersion.js +21 -0
  64. package/cjs/services/migration-service/scripts/index.js +7 -1
  65. package/cjs/services/mint-campaign-service/campaigns/UnlockDotCampaign.js +149 -0
  66. package/cjs/services/mint-campaign-service/campaigns/index.js +13 -0
  67. package/cjs/services/mint-campaign-service/constants.js +11 -0
  68. package/cjs/services/mint-campaign-service/index.js +18 -0
  69. package/cjs/services/notification-service/NotificationService.js +1 -1
  70. package/cjs/services/storage-service/DatabaseService.js +51 -0
  71. package/cjs/services/storage-service/databases/index.js +4 -0
  72. package/cjs/services/storage-service/db-stores/NominatorMetadata.js +3 -3
  73. package/cjs/services/storage-service/db-stores/YieldPoolStore.js +36 -0
  74. package/cjs/services/storage-service/db-stores/YieldPositionStore.js +65 -0
  75. package/cjs/services/transaction-service/event-parser/index.js +58 -0
  76. package/cjs/services/transaction-service/helpers/index.js +3 -1
  77. package/cjs/services/transaction-service/index.js +185 -74
  78. package/cjs/services/transaction-service/utils.js +1 -0
  79. package/cjs/types/campaigns/index.js +16 -0
  80. package/cjs/types/campaigns/unlock-dot.js +1 -0
  81. package/cjs/types/index.js +44 -0
  82. package/cjs/types/ordinal.js +1 -0
  83. package/cjs/types/transaction.js +1 -0
  84. package/cjs/types/yield/actions/index.js +27 -0
  85. package/cjs/types/yield/actions/join/index.js +38 -0
  86. package/cjs/types/yield/actions/join/step.js +47 -0
  87. package/cjs/types/yield/actions/join/submit.js +1 -0
  88. package/cjs/types/yield/actions/join/validate.js +16 -0
  89. package/cjs/types/yield/actions/others.js +1 -0
  90. package/cjs/types/yield/index.js +27 -0
  91. package/cjs/types/yield/info/account/index.js +49 -0
  92. package/cjs/types/yield/info/account/info.js +1 -0
  93. package/cjs/types/yield/info/account/reward.js +1 -0
  94. package/cjs/types/yield/info/account/target.js +32 -0
  95. package/cjs/types/yield/info/account/unstake.js +27 -0
  96. package/cjs/types/yield/info/base.js +41 -0
  97. package/cjs/types/yield/info/chain/index.js +27 -0
  98. package/cjs/types/yield/info/chain/info.js +1 -0
  99. package/cjs/types/yield/info/chain/target.js +1 -0
  100. package/cjs/types/yield/info/index.js +49 -0
  101. package/cjs/types/yield/info/pallet.js +15 -0
  102. package/cjs/utils/fetchStaticData.js +2 -1
  103. package/cjs/utils/index.js +89 -1
  104. package/cjs/utils/object.js +12 -0
  105. package/cjs/utils/yield/index.js +3 -0
  106. package/constants/index.d.ts +2 -0
  107. package/constants/index.js +2 -0
  108. package/koni/api/nft/config.js +33 -23
  109. package/koni/api/nft/index.js +15 -1
  110. package/koni/api/nft/nft.js +2 -23
  111. package/koni/api/nft/ordinal_nft/constants.d.ts +9 -0
  112. package/koni/api/nft/ordinal_nft/constants.js +12 -0
  113. package/koni/api/nft/ordinal_nft/index.d.ts +8 -0
  114. package/koni/api/nft/ordinal_nft/index.js +114 -0
  115. package/koni/api/nft/ordinal_nft/utils.d.ts +2 -0
  116. package/koni/api/nft/ordinal_nft/utils.js +33 -0
  117. package/koni/api/staking/bonding/amplitude.js +11 -9
  118. package/koni/api/staking/bonding/astar.js +9 -8
  119. package/koni/api/staking/bonding/index.d.ts +1 -1
  120. package/koni/api/staking/bonding/index.js +5 -1
  121. package/koni/api/staking/bonding/paraChain.js +12 -10
  122. package/koni/api/staking/bonding/relayChain.d.ts +2 -2
  123. package/koni/api/staking/bonding/relayChain.js +33 -30
  124. package/koni/api/staking/bonding/utils.d.ts +15 -38
  125. package/koni/api/staking/bonding/utils.js +85 -69
  126. package/koni/api/staking/index.js +2 -1
  127. package/koni/api/staking/paraChain.js +7 -6
  128. package/koni/api/staking/relayChain.js +4 -3
  129. package/koni/api/yield/helper/utils.d.ts +10 -0
  130. package/koni/api/yield/helper/utils.js +32 -0
  131. package/koni/background/cron.js +2 -0
  132. package/koni/background/handlers/Extension.d.ts +16 -1
  133. package/koni/background/handlers/Extension.js +306 -30
  134. package/koni/background/handlers/State.d.ts +18 -2
  135. package/koni/background/handlers/State.js +50 -3
  136. package/koni/background/handlers/index.js +4 -2
  137. package/koni/background/subscription.d.ts +5 -1
  138. package/koni/background/subscription.js +90 -20
  139. package/package.json +316 -3
  140. package/services/campaign-service/index.js +9 -6
  141. package/services/chain-service/constants.d.ts +0 -11
  142. package/services/chain-service/constants.js +1 -14
  143. package/services/chain-service/utils.d.ts +1 -0
  144. package/services/chain-service/utils.js +5 -1
  145. package/services/earning-service/constants/abis/compound_finance_v2_abi.json +1235 -0
  146. package/services/earning-service/constants/abis/st_liquid_token_abi.json +1355 -0
  147. package/services/earning-service/constants/chains.d.ts +14 -0
  148. package/services/earning-service/constants/chains.js +21 -0
  149. package/services/earning-service/constants/index.d.ts +2 -0
  150. package/services/earning-service/constants/index.js +5 -0
  151. package/services/earning-service/constants/step.d.ts +3 -0
  152. package/services/earning-service/constants/step.js +10 -0
  153. package/services/earning-service/handlers/base.d.ts +108 -0
  154. package/services/earning-service/handlers/base.js +224 -0
  155. package/services/earning-service/handlers/index.d.ts +5 -0
  156. package/services/earning-service/handlers/index.js +8 -0
  157. package/services/earning-service/handlers/lending/base.d.ts +6 -0
  158. package/services/earning-service/handlers/lending/base.js +12 -0
  159. package/services/earning-service/handlers/lending/index.d.ts +1 -0
  160. package/services/earning-service/handlers/lending/index.js +4 -0
  161. package/services/earning-service/handlers/lending/interlay.d.ts +22 -0
  162. package/services/earning-service/handlers/lending/interlay.js +168 -0
  163. package/services/earning-service/handlers/liquid-staking/acala.d.ts +27 -0
  164. package/services/earning-service/handlers/liquid-staking/acala.js +198 -0
  165. package/services/earning-service/handlers/liquid-staking/base.d.ts +9 -0
  166. package/services/earning-service/handlers/liquid-staking/base.js +35 -0
  167. package/services/earning-service/handlers/liquid-staking/bifrost.d.ts +44 -0
  168. package/services/earning-service/handlers/liquid-staking/bifrost.js +256 -0
  169. package/services/earning-service/handlers/liquid-staking/index.d.ts +4 -0
  170. package/services/earning-service/handlers/liquid-staking/index.js +7 -0
  171. package/services/earning-service/handlers/liquid-staking/parallel.d.ts +27 -0
  172. package/services/earning-service/handlers/liquid-staking/parallel.js +182 -0
  173. package/services/earning-service/handlers/liquid-staking/stella-swap.d.ts +36 -0
  174. package/services/earning-service/handlers/liquid-staking/stella-swap.js +372 -0
  175. package/services/earning-service/handlers/native-staking/amplitude.d.ts +22 -0
  176. package/services/earning-service/handlers/native-staking/amplitude.js +371 -0
  177. package/services/earning-service/handlers/native-staking/astar.d.ts +19 -0
  178. package/services/earning-service/handlers/native-staking/astar.js +444 -0
  179. package/services/earning-service/handlers/native-staking/base-para.d.ts +11 -0
  180. package/services/earning-service/handlers/native-staking/base-para.js +129 -0
  181. package/services/earning-service/handlers/native-staking/base.d.ts +20 -0
  182. package/services/earning-service/handlers/native-staking/base.js +110 -0
  183. package/services/earning-service/handlers/native-staking/index.d.ts +4 -0
  184. package/services/earning-service/handlers/native-staking/index.js +7 -0
  185. package/services/earning-service/handlers/native-staking/para-chain.d.ts +15 -0
  186. package/services/earning-service/handlers/native-staking/para-chain.js +373 -0
  187. package/services/earning-service/handlers/native-staking/relay-chain.d.ts +21 -0
  188. package/services/earning-service/handlers/native-staking/relay-chain.js +531 -0
  189. package/services/earning-service/handlers/nomination-pool/index.d.ts +33 -0
  190. package/services/earning-service/handlers/nomination-pool/index.js +518 -0
  191. package/services/earning-service/handlers/special.d.ts +59 -0
  192. package/services/earning-service/handlers/special.js +404 -0
  193. package/services/earning-service/service.d.ts +40 -0
  194. package/services/earning-service/service.js +343 -0
  195. package/services/earning-service/utils/index.d.ts +18 -0
  196. package/services/earning-service/utils/index.js +112 -0
  197. package/services/event-service/index.d.ts +1 -0
  198. package/services/event-service/index.js +4 -0
  199. package/services/event-service/types.d.ts +8 -0
  200. package/services/keyring-service/index.d.ts +2 -1
  201. package/services/keyring-service/index.js +14 -2
  202. package/services/migration-service/scripts/DeleteEarningData.d.ts +4 -0
  203. package/services/migration-service/scripts/DeleteEarningData.js +13 -0
  204. package/services/migration-service/scripts/EnableEarningChains.d.ts +4 -0
  205. package/services/migration-service/scripts/EnableEarningChains.js +13 -0
  206. package/services/migration-service/scripts/MigrateLedgerAccount.js +1 -1
  207. package/services/migration-service/scripts/MigrateTransactionHistory.js +1 -1
  208. package/services/migration-service/scripts/databases/MigrateEarningHistory.d.ts +4 -0
  209. package/services/migration-service/scripts/databases/MigrateEarningHistory.js +13 -0
  210. package/services/migration-service/scripts/databases/MigrateEarningVersion.d.ts +4 -0
  211. package/services/migration-service/scripts/databases/MigrateEarningVersion.js +13 -0
  212. package/services/migration-service/scripts/index.js +7 -1
  213. package/services/mint-campaign-service/campaigns/UnlockDotCampaign.d.ts +13 -0
  214. package/services/mint-campaign-service/campaigns/UnlockDotCampaign.js +139 -0
  215. package/services/mint-campaign-service/campaigns/index.d.ts +1 -0
  216. package/services/mint-campaign-service/campaigns/index.js +4 -0
  217. package/services/mint-campaign-service/constants.d.ts +1 -0
  218. package/services/mint-campaign-service/constants.js +4 -0
  219. package/services/mint-campaign-service/index.d.ts +7 -0
  220. package/services/mint-campaign-service/index.js +11 -0
  221. package/services/notification-service/NotificationService.js +1 -1
  222. package/services/storage-service/DatabaseService.d.ts +18 -1
  223. package/services/storage-service/DatabaseService.js +51 -0
  224. package/services/storage-service/databases/index.d.ts +3 -1
  225. package/services/storage-service/databases/index.js +4 -0
  226. package/services/storage-service/db-stores/NominatorMetadata.js +3 -3
  227. package/services/storage-service/db-stores/YieldPoolStore.d.ts +10 -0
  228. package/services/storage-service/db-stores/YieldPoolStore.js +28 -0
  229. package/services/storage-service/db-stores/YieldPositionStore.d.ts +9 -0
  230. package/services/storage-service/db-stores/YieldPositionStore.js +57 -0
  231. package/services/subscan-service/index.d.ts +2 -2
  232. package/services/transaction-service/event-parser/index.d.ts +3 -1
  233. package/services/transaction-service/event-parser/index.js +57 -1
  234. package/services/transaction-service/helpers/index.js +3 -1
  235. package/services/transaction-service/index.d.ts +4 -15
  236. package/services/transaction-service/index.js +183 -72
  237. package/services/transaction-service/types.d.ts +2 -0
  238. package/services/transaction-service/utils.js +1 -0
  239. package/types/campaigns/index.d.ts +1 -0
  240. package/types/campaigns/index.js +4 -0
  241. package/types/campaigns/unlock-dot.d.ts +71 -0
  242. package/types/campaigns/unlock-dot.js +1 -0
  243. package/types/index.d.ts +5 -0
  244. package/types/index.js +5 -1
  245. package/types/ordinal.d.ts +69 -0
  246. package/types/ordinal.js +1 -0
  247. package/types/transaction.d.ts +3 -0
  248. package/types/transaction.js +1 -0
  249. package/types/yield/actions/index.d.ts +2 -0
  250. package/types/yield/actions/index.js +5 -0
  251. package/types/yield/actions/join/index.d.ts +3 -0
  252. package/types/yield/actions/join/index.js +6 -0
  253. package/types/yield/actions/join/step.d.ts +94 -0
  254. package/types/yield/actions/join/step.js +46 -0
  255. package/types/yield/actions/join/submit.d.ts +53 -0
  256. package/types/yield/actions/join/submit.js +1 -0
  257. package/types/yield/actions/join/validate.d.ts +18 -0
  258. package/types/yield/actions/join/validate.js +10 -0
  259. package/types/yield/actions/others.d.ts +63 -0
  260. package/types/yield/actions/others.js +1 -0
  261. package/types/yield/index.d.ts +2 -0
  262. package/types/yield/index.js +5 -0
  263. package/types/yield/info/account/index.d.ts +4 -0
  264. package/types/yield/info/account/index.js +7 -0
  265. package/types/yield/info/account/info.d.ts +101 -0
  266. package/types/yield/info/account/info.js +1 -0
  267. package/types/yield/info/account/reward.d.ts +30 -0
  268. package/types/yield/info/account/reward.js +1 -0
  269. package/types/yield/info/account/target.d.ts +43 -0
  270. package/types/yield/info/account/target.js +27 -0
  271. package/types/yield/info/account/unstake.d.ts +31 -0
  272. package/types/yield/info/account/unstake.js +22 -0
  273. package/types/yield/info/base.d.ts +45 -0
  274. package/types/yield/info/base.js +36 -0
  275. package/types/yield/info/chain/index.d.ts +2 -0
  276. package/types/yield/info/chain/index.js +5 -0
  277. package/types/yield/info/chain/info.d.ts +217 -0
  278. package/types/yield/info/chain/info.js +1 -0
  279. package/types/yield/info/chain/target.d.ts +37 -0
  280. package/types/yield/info/chain/target.js +1 -0
  281. package/types/yield/info/index.d.ts +4 -0
  282. package/types/yield/info/index.js +7 -0
  283. package/types/yield/info/pallet.d.ts +143 -0
  284. package/types/yield/info/pallet.js +9 -0
  285. package/utils/fetchStaticData.js +2 -1
  286. package/utils/index.d.ts +5 -0
  287. package/utils/index.js +53 -1
  288. package/utils/object.d.ts +1 -0
  289. package/utils/object.js +6 -0
@@ -0,0 +1,382 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.getStellaswapLiquidStakingContract = 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 _web = require("@subwallet/extension-base/koni/api/tokens/evm/web3");
11
+ var _utils = require("@subwallet/extension-base/services/chain-service/utils");
12
+ var _types = require("@subwallet/extension-base/types");
13
+ var _crossFetch = _interopRequireDefault(require("cross-fetch"));
14
+ var _util = require("@polkadot/util");
15
+ var _constants = require("../../constants");
16
+ var _base = _interopRequireDefault(require("./base"));
17
+ // Copyright 2019-2022 @subwallet/extension-base
18
+ // SPDX-License-Identifier: Apache-2.0
19
+
20
+ const getStellaswapLiquidStakingContract = function (networkKey, assetAddress, evmApi) {
21
+ let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
22
+ // @ts-ignore
23
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument,@typescript-eslint/no-unsafe-member-access
24
+ return new evmApi.api.eth.Contract(_constants.ST_LIQUID_TOKEN_ABI, assetAddress, options);
25
+ };
26
+ exports.getStellaswapLiquidStakingContract = getStellaswapLiquidStakingContract;
27
+ const APR_STATS_URL = 'https://apr-api.stellaswap.com/api/v1/stdot';
28
+ const MAX_INT = '115792089237316195423570985008687907853269984665640564039457584007913129639935';
29
+ class StellaSwapLiquidStakingPoolHandler extends _base.default {
30
+ inputAsset = 'moonbeam-LOCAL-xcDOT';
31
+ altInputAsset = '';
32
+ derivativeAssets = ['moonbeam-ERC20-stDOT-0xbc7E02c4178a7dF7d3E564323a5c359dc96C4db4'];
33
+ rewardAssets = ['moonbeam-LOCAL-xcDOT'];
34
+ feeAssets = ['moonbeam-NATIVE-GLMR'];
35
+ /** @inner */
36
+ allowDefaultUnstake = true;
37
+ /** @inner */
38
+ allowFastUnstake = false;
39
+ transactionChainType = _KoniTypes.ChainType.EVM;
40
+ constructor(state, chain) {
41
+ super(state, chain);
42
+ this.slug = 'xcDOT___liquid_staking___stellaswap';
43
+ this.name = 'Stellaswap Liquid Staking';
44
+ this._logo = 'stellaswap';
45
+ this.shortName = 'Stellaswap';
46
+ }
47
+ getDescription() {
48
+ return 'Earn rewards by staking xcDOT for stDOT';
49
+ }
50
+
51
+ /* Subscribe pool info */
52
+
53
+ async getPoolStat() {
54
+ const evmApi = this.evmApi;
55
+ const derivativeTokenSlug = this.derivativeAssets[0];
56
+ const derivativeTokenInfo = this.state.getAssetBySlug(derivativeTokenSlug);
57
+ const stakingContract = getStellaswapLiquidStakingContract(this.chain, (0, _utils._getContractAddressOfToken)(derivativeTokenInfo), evmApi);
58
+ const aprPromise = new Promise(function (resolve) {
59
+ (0, _crossFetch.default)(APR_STATS_URL, {
60
+ method: 'GET'
61
+ }).then(res => {
62
+ resolve(res.json());
63
+ }).catch(console.error);
64
+ });
65
+ const sampleTokenShare = 10 ** (0, _utils._getAssetDecimals)(derivativeTokenInfo);
66
+
67
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
68
+ const tvlCall = stakingContract.methods.fundRaisedBalance();
69
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
70
+ const exchangeRateCall = stakingContract.methods.getPooledTokenByShares(sampleTokenShare);
71
+
72
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
73
+ const [aprObject, tvl, equivalentTokenShare] = await Promise.all([aprPromise,
74
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
75
+ tvlCall.call(),
76
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
77
+ exchangeRateCall.call()]);
78
+ const exchangeRate = equivalentTokenShare / 10 ** (0, _utils._getAssetDecimals)(derivativeTokenInfo);
79
+ return {
80
+ ...this.baseInfo,
81
+ type: this.type,
82
+ metadata: {
83
+ ...this.metadataInfo,
84
+ description: this.getDescription()
85
+ },
86
+ statistic: {
87
+ assetEarning: [{
88
+ slug: this.rewardAssets[0],
89
+ apr: aprObject.result,
90
+ exchangeRate: exchangeRate
91
+ }],
92
+ unstakingPeriod: 24 * 28,
93
+ maxCandidatePerFarmer: 1,
94
+ maxWithdrawalRequestPerFarmer: 1,
95
+ minJoinPool: '0',
96
+ minWithdrawal: '0',
97
+ totalApr: aprObject.result,
98
+ tvl: tvl.toString()
99
+ }
100
+ };
101
+ }
102
+
103
+ /* Subscribe pool info */
104
+
105
+ /* Subscribe pool position */
106
+
107
+ // eslint-disable-next-line @typescript-eslint/require-await
108
+ async subscribePoolPosition(useAddresses, resultCallback) {
109
+ var _this$derivativeAsset;
110
+ let cancel = false;
111
+ const evmApi = this.evmApi;
112
+ const derivativeTokenSlug = ((_this$derivativeAsset = this.derivativeAssets) === null || _this$derivativeAsset === void 0 ? void 0 : _this$derivativeAsset[0]) || '';
113
+ const derivativeTokenInfo = this.state.getAssetBySlug(derivativeTokenSlug);
114
+ const contract = getStellaswapLiquidStakingContract(this.chain, (0, _utils._getContractAddressOfToken)(derivativeTokenInfo), evmApi);
115
+ const getTokenBalance = () => {
116
+ if (!cancel) {
117
+ useAddresses.map(async address => {
118
+ if (!cancel) {
119
+ return;
120
+ }
121
+
122
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
123
+ const balance = await contract.methods.balanceOf(address).call();
124
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
125
+ const unbondedObject = await contract.methods.getUnbonded(address).call();
126
+ const unstakings = [];
127
+ let unlockBalance = _util.BN_ZERO;
128
+ if (parseInt(unbondedObject.unbonded) > 0) {
129
+ unlockBalance = unlockBalance.add(new _util.BN(unbondedObject.unbonded));
130
+ unstakings.push({
131
+ chain: this.chain,
132
+ claimable: unbondedObject.unbonded,
133
+ status: _types.UnstakingStatus.CLAIMABLE,
134
+ waitingTime: 0
135
+ });
136
+ }
137
+ if (parseInt(unbondedObject.waiting) > 0) {
138
+ unlockBalance = unlockBalance.add(new _util.BN(unbondedObject.waiting));
139
+ unstakings.push({
140
+ chain: this.chain,
141
+ claimable: unbondedObject.waiting,
142
+ status: _types.UnstakingStatus.UNLOCKING,
143
+ waitingTime: 20 // TODO: Recheck
144
+ });
145
+ }
146
+
147
+ const totalBalance = new _util.BN(balance).add(unlockBalance);
148
+ const result = {
149
+ ...this.baseInfo,
150
+ type: this.type,
151
+ address,
152
+ balanceToken: this.inputAsset,
153
+ totalStake: totalBalance.toString(),
154
+ activeStake: balance.toString(),
155
+ unstakeBalance: unlockBalance.toString(),
156
+ isBondedBefore: totalBalance.gt(_util.BN_ZERO),
157
+ derivativeToken: derivativeTokenSlug,
158
+ status: _types.EarningStatus.EARNING_REWARD,
159
+ nominations: [],
160
+ unstakings
161
+ };
162
+ resultCallback(result);
163
+ });
164
+ }
165
+ };
166
+ getTokenBalance();
167
+ const interval = setInterval(getTokenBalance, 30000);
168
+ return () => {
169
+ cancel = true;
170
+ clearInterval(interval);
171
+ };
172
+ }
173
+
174
+ /* Subscribe pool position */
175
+
176
+ /* Join pool action */
177
+
178
+ get submitJoinStepInfo() {
179
+ return {
180
+ name: 'Mint stDOT',
181
+ type: _types.YieldStepType.MINT_STDOT
182
+ };
183
+ }
184
+ async getTokenApproveStep(params) {
185
+ const evmApi = this.evmApi;
186
+ const derivativeTokenSlug = this.derivativeAssets[0];
187
+ const derivativeTokenInfo = this.state.getAssetBySlug(derivativeTokenSlug);
188
+ const inputTokenSlug = this.inputAsset;
189
+ const inputTokenInfo = this.state.getAssetBySlug(inputTokenSlug);
190
+ const inputTokenContract = (0, _web.getERC20Contract)(this.chain, (0, _utils._getContractAddressOfToken)(inputTokenInfo), this.state.getEvmApiMap());
191
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
192
+ const allowanceCall = inputTokenContract.methods.allowance(params.address, (0, _utils._getContractAddressOfToken)(derivativeTokenInfo)); // TODO
193
+
194
+ const [allowance, gasPrice] = await Promise.all([
195
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
196
+ await allowanceCall.call(), evmApi.api.eth.getGasPrice()]);
197
+ if (!allowance || parseInt(allowance) <= 0) {
198
+ const step = {
199
+ name: 'Authorize token approval',
200
+ type: _types.YieldStepType.TOKEN_APPROVAL
201
+ };
202
+
203
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
204
+ const estimatedGas = await allowanceCall.estimateGas();
205
+ const fee = {
206
+ slug: this.feeAssets[0],
207
+ amount: (estimatedGas * parseInt(gasPrice)).toString()
208
+ };
209
+ return [step, fee];
210
+ }
211
+ return undefined;
212
+ }
213
+ async getSubmitStepFee(params) {
214
+ const evmApi = this.evmApi;
215
+ const derivativeTokenSlug = this.derivativeAssets[0];
216
+ const derivativeTokenInfo = this.state.getAssetBySlug(derivativeTokenSlug);
217
+ if (new _util.BN(params.amount).gt(_util.BN_ZERO)) {
218
+ const stakingContract = getStellaswapLiquidStakingContract(this.chain, (0, _utils._getContractAddressOfToken)(derivativeTokenInfo), evmApi);
219
+
220
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
221
+ const depositCall = stakingContract.methods.deposit(params.amount);
222
+
223
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
224
+ const estimatedDepositGas = await depositCall.estimateGas();
225
+ const gasPrice = await evmApi.api.eth.getGasPrice();
226
+ return {
227
+ slug: this.feeAssets[0],
228
+ amount: (estimatedDepositGas * parseInt(gasPrice)).toString()
229
+ };
230
+ } else {
231
+ return {
232
+ slug: this.feeAssets[0],
233
+ amount: '0'
234
+ };
235
+ }
236
+ }
237
+ async generateOptimalPath(params) {
238
+ const result = {
239
+ totalFee: [{
240
+ slug: ''
241
+ }],
242
+ steps: [_constants.DEFAULT_YIELD_FIRST_STEP]
243
+ };
244
+ try {
245
+ /* Token approve step */
246
+
247
+ const approveStep = await this.getTokenApproveStep(params);
248
+ if (approveStep) {
249
+ const [step, fee] = approveStep;
250
+ result.steps.push({
251
+ id: result.steps.length,
252
+ ...step
253
+ });
254
+ result.totalFee.push(fee);
255
+ }
256
+
257
+ /* Token approve step */
258
+
259
+ /* Submit step */
260
+
261
+ const submitFee = await this.getSubmitStepFee(params);
262
+ result.steps.push({
263
+ id: result.steps.length,
264
+ ...this.submitJoinStepInfo
265
+ });
266
+ result.totalFee.push(submitFee);
267
+
268
+ /* Submit step */
269
+
270
+ return result;
271
+ } catch (e) {
272
+ const errorMessage = e.message;
273
+ if (errorMessage.includes('network')) {
274
+ result.connectionError = errorMessage.split(' ')[0];
275
+ }
276
+
277
+ /* Submit step */
278
+
279
+ result.steps.push({
280
+ id: result.steps.length,
281
+ ...this.submitJoinStepInfo
282
+ });
283
+ result.totalFee.push({
284
+ slug: this.feeAssets[0],
285
+ amount: '0'
286
+ });
287
+
288
+ /* Submit step */
289
+
290
+ return result;
291
+ }
292
+ }
293
+ async validateTokenApproveStep(params, path) {
294
+ return Promise.resolve([]);
295
+ }
296
+ async handleTokenApproveStep(data, path) {
297
+ const {
298
+ address
299
+ } = data;
300
+ const inputTokenSlug = this.inputAsset;
301
+ const inputTokenInfo = this.state.getAssetBySlug(inputTokenSlug);
302
+ const inputTokenContract = (0, _web.getERC20Contract)(this.chain, (0, _utils._getContractAddressOfToken)(inputTokenInfo), this.state.getEvmApiMap());
303
+
304
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
305
+ const approveCall = inputTokenContract.methods.approve(address, MAX_INT);
306
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
307
+ const approveEncodedCall = approveCall.encodeABI();
308
+ const transactionObject = {
309
+ from: address,
310
+ to: (0, _utils._getContractAddressOfToken)(inputTokenInfo),
311
+ data: approveEncodedCall
312
+ };
313
+ return Promise.resolve({
314
+ txChain: this.chain,
315
+ extrinsicType: _KoniTypes.ExtrinsicType.EVM_EXECUTE,
316
+ extrinsic: transactionObject,
317
+ txData: transactionObject,
318
+ transferNativeAmount: '0'
319
+ });
320
+ }
321
+
322
+ // eslint-disable-next-line @typescript-eslint/require-await
323
+ async handleSubmitStep(data, path) {
324
+ const {
325
+ address,
326
+ amount
327
+ } = data;
328
+ const evmApi = this.evmApi;
329
+ const derivativeTokenSlug = this.derivativeAssets[0];
330
+ const derivativeTokenInfo = this.state.getAssetBySlug(derivativeTokenSlug);
331
+ const stakingContract = getStellaswapLiquidStakingContract(this.chain, (0, _utils._getContractAddressOfToken)(derivativeTokenInfo), evmApi);
332
+
333
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
334
+ const depositCall = stakingContract.methods.deposit(amount); // TODO: referral
335
+
336
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
337
+ const depositEncodedCall = depositCall.encodeABI();
338
+ const transactionObject = {
339
+ from: address,
340
+ to: (0, _utils._getContractAddressOfToken)(derivativeTokenInfo),
341
+ data: depositEncodedCall
342
+ };
343
+ return {
344
+ txChain: this.chain,
345
+ extrinsicType: _KoniTypes.ExtrinsicType.MINT_STDOT,
346
+ extrinsic: transactionObject,
347
+ txData: data,
348
+ transferNativeAmount: '0'
349
+ };
350
+ }
351
+
352
+ /* Join pool action */
353
+
354
+ /* Leave pool action */
355
+
356
+ async handleYieldRedeem(amount, address, selectedTarget) {
357
+ return Promise.reject(new _TransactionError.TransactionError(_KoniTypes.BasicTxErrorType.UNSUPPORTED));
358
+ }
359
+
360
+ // eslint-disable-next-line @typescript-eslint/require-await
361
+ async handleYieldUnstake(amount, address, selectedTarget) {
362
+ const evmApi = this.evmApi;
363
+ const derivativeTokenSlug = this.derivativeAssets[0];
364
+ const derivativeTokenInfo = this.state.getAssetBySlug(derivativeTokenSlug);
365
+ const stakingContract = getStellaswapLiquidStakingContract(this.chain, (0, _utils._getContractAddressOfToken)(derivativeTokenInfo), evmApi);
366
+
367
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
368
+ const redeemCall = stakingContract.methods.redeem(amount);
369
+
370
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
371
+ const redeemEncodedCall = redeemCall.encodeABI();
372
+ const transaction = {
373
+ from: address,
374
+ to: (0, _utils._getContractAddressOfToken)(derivativeTokenInfo),
375
+ data: redeemEncodedCall
376
+ };
377
+ return [_KoniTypes.ExtrinsicType.STAKING_UNBOND, transaction];
378
+ }
379
+
380
+ /* Leave pool action */
381
+ }
382
+ exports.default = StellaSwapLiquidStakingPoolHandler;