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