@subwallet/extension-base 1.1.28-1 → 1.1.28-beta.2

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 +57 -4
  26. package/cjs/koni/background/handlers/index.js +4 -2
  27. package/cjs/koni/background/subscription.js +89 -19
  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 +220 -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 +170 -0
  39. package/cjs/services/earning-service/handlers/liquid-staking/acala.js +198 -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 +259 -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 +182 -0
  44. package/cjs/services/earning-service/handlers/liquid-staking/stella-swap.js +375 -0
  45. package/cjs/services/earning-service/handlers/native-staking/amplitude.js +373 -0
  46. package/cjs/services/earning-service/handlers/native-staking/astar.js +446 -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 +375 -0
  51. package/cjs/services/earning-service/handlers/native-staking/relay-chain.js +529 -0
  52. package/cjs/services/earning-service/handlers/nomination-pool/index.js +521 -0
  53. package/cjs/services/earning-service/handlers/special.js +411 -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 +180 -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 +56 -4
  136. package/koni/background/handlers/index.js +4 -2
  137. package/koni/background/subscription.d.ts +5 -1
  138. package/koni/background/subscription.js +91 -21
  139. package/package.json +317 -4
  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 +107 -0
  154. package/services/earning-service/handlers/base.js +213 -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 +162 -0
  163. package/services/earning-service/handlers/liquid-staking/acala.d.ts +27 -0
  164. package/services/earning-service/handlers/liquid-staking/acala.js +190 -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 +248 -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 +174 -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 +365 -0
  175. package/services/earning-service/handlers/native-staking/amplitude.d.ts +22 -0
  176. package/services/earning-service/handlers/native-staking/amplitude.js +364 -0
  177. package/services/earning-service/handlers/native-staking/astar.d.ts +19 -0
  178. package/services/earning-service/handlers/native-staking/astar.js +436 -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 +367 -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 +520 -0
  189. package/services/earning-service/handlers/nomination-pool/index.d.ts +33 -0
  190. package/services/earning-service/handlers/nomination-pool/index.js +511 -0
  191. package/services/earning-service/handlers/special.d.ts +58 -0
  192. package/services/earning-service/handlers/special.js +403 -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 +178 -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 +208 -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,375 @@
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 _bn = require("bn.js");
14
+ var _crossFetch = _interopRequireDefault(require("cross-fetch"));
15
+ var _util = require("@polkadot/util");
16
+ var _constants = require("../../constants");
17
+ var _base = _interopRequireDefault(require("./base"));
18
+ // Copyright 2019-2022 @subwallet/extension-base
19
+ // SPDX-License-Identifier: Apache-2.0
20
+
21
+ const getStellaswapLiquidStakingContract = function (networkKey, assetAddress, evmApi) {
22
+ let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
23
+ // @ts-ignore
24
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument,@typescript-eslint/no-unsafe-member-access
25
+ return new evmApi.api.eth.Contract(_constants.ST_LIQUID_TOKEN_ABI, assetAddress, options);
26
+ };
27
+ exports.getStellaswapLiquidStakingContract = getStellaswapLiquidStakingContract;
28
+ const APR_STATS_URL = 'https://apr-api.stellaswap.com/api/v1/stdot';
29
+ const MAX_INT = '115792089237316195423570985008687907853269984665640564039457584007913129639935';
30
+ class StellaSwapLiquidStakingPoolHandler extends _base.default {
31
+ inputAsset = 'moonbeam-LOCAL-xcDOT';
32
+ altInputAsset = '';
33
+ derivativeAssets = ['moonbeam-ERC20-stDOT-0xbc7E02c4178a7dF7d3E564323a5c359dc96C4db4'];
34
+ rewardAssets = ['moonbeam-LOCAL-xcDOT'];
35
+ feeAssets = ['moonbeam-NATIVE-GLMR'];
36
+ /** @inner */
37
+ allowDefaultUnstake = true;
38
+ /** @inner */
39
+ allowFastUnstake = false;
40
+ transactionChainType = _KoniTypes.ChainType.EVM;
41
+ constructor(state, chain) {
42
+ super(state, chain);
43
+ this.slug = 'xcDOT___liquid_staking___stellaswap';
44
+ this.name = 'Stellaswap Liquid Staking';
45
+ this._logo = 'stellaswap';
46
+ this.shortName = 'Stellaswap';
47
+ }
48
+ getDescription() {
49
+ return 'Earn rewards by staking xcDOT for stDOT';
50
+ }
51
+
52
+ /* Subscribe pool info */
53
+
54
+ async getPoolStat() {
55
+ const evmApi = this.evmApi;
56
+ const derivativeTokenSlug = this.derivativeAssets[0];
57
+ const derivativeTokenInfo = this.state.getAssetBySlug(derivativeTokenSlug);
58
+ const stakingContract = getStellaswapLiquidStakingContract(this.chain, (0, _utils._getContractAddressOfToken)(derivativeTokenInfo), evmApi);
59
+ const aprPromise = new Promise(function (resolve) {
60
+ (0, _crossFetch.default)(APR_STATS_URL, {
61
+ method: 'GET'
62
+ }).then(res => {
63
+ resolve(res.json());
64
+ }).catch(console.error);
65
+ });
66
+ const sampleTokenShare = 10 ** (0, _utils._getAssetDecimals)(derivativeTokenInfo);
67
+
68
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
69
+ const tvlCall = stakingContract.methods.fundRaisedBalance();
70
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
71
+ const exchangeRateCall = stakingContract.methods.getPooledTokenByShares(sampleTokenShare);
72
+
73
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
74
+ const [aprObject, tvl, equivalentTokenShare] = await Promise.all([aprPromise,
75
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
76
+ tvlCall.call(),
77
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
78
+ exchangeRateCall.call()]);
79
+ const exchangeRate = equivalentTokenShare / 10 ** (0, _utils._getAssetDecimals)(derivativeTokenInfo);
80
+ return {
81
+ ...this.baseInfo,
82
+ type: this.type,
83
+ metadata: {
84
+ ...this.metadataInfo,
85
+ description: this.getDescription()
86
+ },
87
+ statistic: {
88
+ assetEarning: [{
89
+ slug: this.rewardAssets[0],
90
+ apr: aprObject.result,
91
+ exchangeRate: exchangeRate
92
+ }],
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 _bn.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 _bn.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 _bn.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
+ const stakingContract = getStellaswapLiquidStakingContract(this.chain, (0, _utils._getContractAddressOfToken)(derivativeTokenInfo), evmApi);
218
+
219
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
220
+ const depositCall = stakingContract.methods.deposit(params.amount);
221
+
222
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
223
+ const estimatedDepositGas = await depositCall.estimateGas();
224
+ const gasPrice = await evmApi.api.eth.getGasPrice();
225
+ return {
226
+ slug: this.feeAssets[0],
227
+ amount: (estimatedDepositGas * parseInt(gasPrice)).toString()
228
+ };
229
+ }
230
+ async generateOptimalPath(params) {
231
+ const result = {
232
+ totalFee: [{
233
+ slug: ''
234
+ }],
235
+ steps: [_constants.DEFAULT_YIELD_FIRST_STEP]
236
+ };
237
+ try {
238
+ /* Token approve step */
239
+
240
+ const approveStep = await this.getTokenApproveStep(params);
241
+ if (approveStep) {
242
+ const [step, fee] = approveStep;
243
+ result.steps.push({
244
+ id: result.steps.length,
245
+ ...step
246
+ });
247
+ result.totalFee.push(fee);
248
+ }
249
+
250
+ /* Token approve step */
251
+
252
+ /* Submit step */
253
+
254
+ const submitFee = await this.getSubmitStepFee(params);
255
+ result.steps.push({
256
+ id: result.steps.length,
257
+ ...this.submitJoinStepInfo
258
+ });
259
+ result.totalFee.push(submitFee);
260
+
261
+ /* Submit step */
262
+
263
+ return result;
264
+ } catch (e) {
265
+ const errorMessage = e.message;
266
+ if (errorMessage.includes('network')) {
267
+ result.connectionError = errorMessage.split(' ')[0];
268
+ }
269
+
270
+ /* Submit step */
271
+
272
+ result.steps.push({
273
+ id: result.steps.length,
274
+ ...this.submitJoinStepInfo
275
+ });
276
+ result.totalFee.push({
277
+ slug: this.feeAssets[0],
278
+ amount: '0'
279
+ });
280
+
281
+ /* Submit step */
282
+
283
+ return result;
284
+ }
285
+ }
286
+ async validateTokenApproveStep(params, path) {
287
+ return Promise.resolve([]);
288
+ }
289
+ async handleTokenApproveStep(data, path) {
290
+ const {
291
+ address
292
+ } = data;
293
+ const inputTokenSlug = this.inputAsset;
294
+ const inputTokenInfo = this.state.getAssetBySlug(inputTokenSlug);
295
+ const inputTokenContract = (0, _web.getERC20Contract)(this.chain, (0, _utils._getContractAddressOfToken)(inputTokenInfo), this.state.getEvmApiMap());
296
+
297
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
298
+ const approveCall = inputTokenContract.methods.approve(address, MAX_INT);
299
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
300
+ const approveEncodedCall = approveCall.encodeABI();
301
+ const transactionObject = {
302
+ from: address,
303
+ to: (0, _utils._getContractAddressOfToken)(inputTokenInfo),
304
+ data: approveEncodedCall
305
+ };
306
+ return Promise.resolve({
307
+ txChain: this.chain,
308
+ extrinsicType: _KoniTypes.ExtrinsicType.EVM_EXECUTE,
309
+ extrinsic: transactionObject,
310
+ txData: transactionObject,
311
+ transferNativeAmount: '0'
312
+ });
313
+ }
314
+
315
+ // eslint-disable-next-line @typescript-eslint/require-await
316
+ async handleSubmitStep(data, path) {
317
+ const {
318
+ address,
319
+ amount
320
+ } = data;
321
+ const evmApi = this.evmApi;
322
+ const derivativeTokenSlug = this.derivativeAssets[0];
323
+ const derivativeTokenInfo = this.state.getAssetBySlug(derivativeTokenSlug);
324
+ const stakingContract = getStellaswapLiquidStakingContract(this.chain, (0, _utils._getContractAddressOfToken)(derivativeTokenInfo), evmApi);
325
+
326
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
327
+ const depositCall = stakingContract.methods.deposit(amount); // TODO: referral
328
+
329
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
330
+ const depositEncodedCall = depositCall.encodeABI();
331
+ const transactionObject = {
332
+ from: address,
333
+ to: (0, _utils._getContractAddressOfToken)(derivativeTokenInfo),
334
+ data: depositEncodedCall
335
+ };
336
+ return {
337
+ txChain: this.chain,
338
+ extrinsicType: _KoniTypes.ExtrinsicType.MINT_STDOT,
339
+ extrinsic: transactionObject,
340
+ txData: data,
341
+ transferNativeAmount: '0'
342
+ };
343
+ }
344
+
345
+ /* Join pool action */
346
+
347
+ /* Leave pool action */
348
+
349
+ async handleYieldRedeem(amount, address, selectedTarget) {
350
+ return Promise.reject(new _TransactionError.TransactionError(_KoniTypes.BasicTxErrorType.UNSUPPORTED));
351
+ }
352
+
353
+ // eslint-disable-next-line @typescript-eslint/require-await
354
+ async handleYieldUnstake(amount, address, selectedTarget) {
355
+ const evmApi = this.evmApi;
356
+ const derivativeTokenSlug = this.derivativeAssets[0];
357
+ const derivativeTokenInfo = this.state.getAssetBySlug(derivativeTokenSlug);
358
+ const stakingContract = getStellaswapLiquidStakingContract(this.chain, (0, _utils._getContractAddressOfToken)(derivativeTokenInfo), evmApi);
359
+
360
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
361
+ const redeemCall = stakingContract.methods.redeem(amount);
362
+
363
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
364
+ const redeemEncodedCall = redeemCall.encodeABI();
365
+ const transaction = {
366
+ from: address,
367
+ to: (0, _utils._getContractAddressOfToken)(derivativeTokenInfo),
368
+ data: redeemEncodedCall
369
+ };
370
+ return [_KoniTypes.ExtrinsicType.STAKING_UNBOND, transaction];
371
+ }
372
+
373
+ /* Leave pool action */
374
+ }
375
+ exports.default = StellaSwapLiquidStakingPoolHandler;