@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,230 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _KoniTypes = require("@subwallet/extension-base/background/KoniTypes");
8
+ var _constants = require("@subwallet/extension-base/services/earning-service/constants");
9
+ var _util = require("@polkadot/util");
10
+ // Copyright 2019-2022 @subwallet/extension-base
11
+ // SPDX-License-Identifier: Apache-2.0
12
+
13
+ /**
14
+ * @class BasePoolHandler
15
+ * @description Base pool handler
16
+ * */
17
+ class BasePoolHandler {
18
+ /** Koni state */
19
+
20
+ /** Pool's chain */
21
+
22
+ /** Pool's logo */
23
+
24
+ /** Pool's slug */
25
+
26
+ /** Pool's type */
27
+
28
+ /** Pool's name */
29
+
30
+ /** Pool's short name */
31
+
32
+ /** Pool's transaction type */
33
+ transactionChainType = _KoniTypes.ChainType.SUBSTRATE;
34
+
35
+ /**
36
+ * @constructor
37
+ * @param {KoniState} state - Koni state
38
+ * @param {string} chain - Pool's chain
39
+ * */
40
+ constructor(state, chain) {
41
+ this.state = state;
42
+ this.chain = chain;
43
+ this._logo = chain;
44
+ }
45
+ get logo() {
46
+ return this._logo;
47
+ }
48
+ get group() {
49
+ const groupSlug = this.nativeToken.multiChainAsset;
50
+ return groupSlug || this.nativeToken.slug;
51
+ }
52
+ get isActive() {
53
+ return this.state.activeChainSlugs.includes(this.chain);
54
+ }
55
+ get substrateApi() {
56
+ return this.state.getSubstrateApi(this.chain);
57
+ }
58
+ get evmApi() {
59
+ return this.state.getEvmApi(this.chain);
60
+ }
61
+ get chainInfo() {
62
+ return this.state.getChainInfo(this.chain);
63
+ }
64
+ get nativeToken() {
65
+ return this.state.getNativeTokenInfo(this.chain);
66
+ }
67
+ get baseInfo() {
68
+ return {
69
+ group: this.group,
70
+ chain: this.chain,
71
+ slug: this.slug
72
+ };
73
+ }
74
+ get maintainBalance() {
75
+ const decimals = this.nativeToken.decimals || 0;
76
+ const defaultMaintainBalance = new _util.BN(1).mul(_util.BN_TEN.pow(new _util.BN(decimals)));
77
+ const ed = new _util.BN(this.nativeToken.minAmount || '0');
78
+ const maintainBalance = ed.gt(defaultMaintainBalance) ? ed.mul(new _util.BN(1.5)) : defaultMaintainBalance;
79
+ return maintainBalance.toString();
80
+ }
81
+ get metadataInfo() {
82
+ return {
83
+ name: this.name,
84
+ shortName: this.shortName,
85
+ logo: this.logo,
86
+ inputAsset: this.nativeToken.slug,
87
+ isAvailable: true,
88
+ allowCancelUnstaking: false,
89
+ maintainAsset: this.nativeToken.slug,
90
+ maintainBalance: this.maintainBalance
91
+ };
92
+ }
93
+
94
+ /** Can mint when haven't enough native token (use input token for fee) */
95
+ get isPoolSupportAlternativeFee() {
96
+ return false;
97
+ }
98
+ async getPoolInfo() {
99
+ return this.state.dbService.getYieldPool(this.slug);
100
+ }
101
+ async getPoolPosition(address) {
102
+ return this.state.dbService.getYieldPositionByAddressAndSlug(address, this.slug);
103
+ }
104
+
105
+ /* Subscribe data */
106
+
107
+ /** Subscribe pool info */
108
+
109
+ /* Subscribe data */
110
+
111
+ /* Join action */
112
+
113
+ /* Early validate */
114
+
115
+ earlyValidate(request) {
116
+ return Promise.resolve({
117
+ passed: false
118
+ });
119
+ }
120
+
121
+ /* Early validate */
122
+
123
+ /* Generate steps */
124
+
125
+ /**
126
+ * @function firstStepFee
127
+ * */
128
+ get firstStepFee() {
129
+ return {
130
+ slug: ''
131
+ };
132
+ }
133
+
134
+ /**
135
+ * @function defaultSubmitStep
136
+ * @description Default submit step data
137
+ * */
138
+
139
+ /**
140
+ * @async
141
+ * @function getTokenApproveStep
142
+ * @param {OptimalYieldPathParams} params - base param to join pool
143
+ * @description Generate token approve step data
144
+ * */
145
+ async getTokenApproveStep(params) {
146
+ return Promise.resolve(undefined);
147
+ }
148
+
149
+ /**
150
+ * @async
151
+ * @function getXcmStep
152
+ * @param {OptimalYieldPathParams} params - base param to join pool
153
+ * @description Generate token approve step data
154
+ * */
155
+ async getXcmStep(params) {
156
+ return Promise.resolve(undefined);
157
+ }
158
+
159
+ /**
160
+ * @async
161
+ * @function getSubmitStep
162
+ * @param {OptimalYieldPathParams} params - base param to join pool
163
+ * @description Generate token approve step data
164
+ * */
165
+
166
+ /** Generate the optimal steps to join pool */
167
+ async generateOptimalPath(params) {
168
+ const result = {
169
+ totalFee: [this.firstStepFee],
170
+ steps: [_constants.DEFAULT_YIELD_FIRST_STEP]
171
+ };
172
+ try {
173
+ const stepFunctions = [this.getTokenApproveStep, this.getXcmStep, this.getSubmitStep];
174
+ for (const stepFunction of stepFunctions) {
175
+ const step = await stepFunction.bind(this, params)();
176
+ if (step) {
177
+ const [info, fee] = step;
178
+ result.steps.push({
179
+ id: result.steps.length,
180
+ ...info
181
+ });
182
+ result.totalFee.push(fee);
183
+ }
184
+ }
185
+ return result;
186
+ } catch (e) {
187
+ const errorMessage = e.message;
188
+ if (errorMessage.includes('network')) {
189
+ result.connectionError = errorMessage.split(' ')[0];
190
+ }
191
+
192
+ /* Submit step */
193
+
194
+ const [step, fee] = this.defaultSubmitStep;
195
+ result.steps.push({
196
+ id: result.steps.length,
197
+ ...step
198
+ });
199
+ result.totalFee.push(fee);
200
+
201
+ /* Submit step */
202
+
203
+ return result;
204
+ }
205
+ }
206
+
207
+ /* Generate steps */
208
+
209
+ /* Validate */
210
+
211
+ /** Validate param to join the pool */
212
+
213
+ /** Create `transaction` to leave the pool */
214
+ async handleYieldLeave(fastLeave, amount, address, selectedTarget) {
215
+ if (fastLeave) {
216
+ return this.handleYieldRedeem(amount, address, selectedTarget);
217
+ } else {
218
+ return this.handleYieldUnstake(amount, address, selectedTarget);
219
+ }
220
+ }
221
+
222
+ /* Leave action */
223
+
224
+ /* Other actions */
225
+
226
+ /** Create `transaction` to withdraw unstaked amount */
227
+
228
+ /* Other actions */
229
+ }
230
+ exports.default = BasePoolHandler;
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ var _exportNames = {
8
+ BasePoolHandler: true,
9
+ NominationPoolHandler: true
10
+ };
11
+ Object.defineProperty(exports, "BasePoolHandler", {
12
+ enumerable: true,
13
+ get: function () {
14
+ return _base.default;
15
+ }
16
+ });
17
+ Object.defineProperty(exports, "NominationPoolHandler", {
18
+ enumerable: true,
19
+ get: function () {
20
+ return _nominationPool.default;
21
+ }
22
+ });
23
+ var _base = _interopRequireDefault(require("./base"));
24
+ var _nominationPool = _interopRequireDefault(require("./nomination-pool"));
25
+ var _lending = require("./lending");
26
+ Object.keys(_lending).forEach(function (key) {
27
+ if (key === "default" || key === "__esModule") return;
28
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
29
+ if (key in exports && exports[key] === _lending[key]) return;
30
+ Object.defineProperty(exports, key, {
31
+ enumerable: true,
32
+ get: function () {
33
+ return _lending[key];
34
+ }
35
+ });
36
+ });
37
+ var _liquidStaking = require("./liquid-staking");
38
+ Object.keys(_liquidStaking).forEach(function (key) {
39
+ if (key === "default" || key === "__esModule") return;
40
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
41
+ if (key in exports && exports[key] === _liquidStaking[key]) return;
42
+ Object.defineProperty(exports, key, {
43
+ enumerable: true,
44
+ get: function () {
45
+ return _liquidStaking[key];
46
+ }
47
+ });
48
+ });
49
+ var _nativeStaking = require("./native-staking");
50
+ Object.keys(_nativeStaking).forEach(function (key) {
51
+ if (key === "default" || key === "__esModule") return;
52
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
53
+ if (key in exports && exports[key] === _nativeStaking[key]) return;
54
+ Object.defineProperty(exports, key, {
55
+ enumerable: true,
56
+ get: function () {
57
+ return _nativeStaking[key];
58
+ }
59
+ });
60
+ });
@@ -0,0 +1,20 @@
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 _types = require("@subwallet/extension-base/types");
9
+ var _special = _interopRequireDefault(require("../special"));
10
+ // Copyright 2019-2022 @subwallet/extension-base
11
+ // SPDX-License-Identifier: Apache-2.0
12
+
13
+ class BaseLendingPoolHandler extends _special.default {
14
+ type = _types.YieldPoolType.LENDING;
15
+
16
+ /* Subscribe pool info */
17
+
18
+ /* Subscribe pool info */
19
+ }
20
+ exports.default = BaseLendingPoolHandler;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ Object.defineProperty(exports, "InterlayLendingPoolHandler", {
8
+ enumerable: true,
9
+ get: function () {
10
+ return _interlay.default;
11
+ }
12
+ });
13
+ var _interlay = _interopRequireDefault(require("./interlay"));
@@ -0,0 +1,176 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = void 0;
8
+ var _TransactionError = require("@subwallet/extension-base/background/errors/TransactionError");
9
+ var _KoniTypes = require("@subwallet/extension-base/background/KoniTypes");
10
+ var _utils = require("@subwallet/extension-base/services/chain-service/utils");
11
+ var _types = require("@subwallet/extension-base/types");
12
+ var _util = require("@polkadot/util");
13
+ var _constants = require("../../constants");
14
+ var _base = _interopRequireDefault(require("./base"));
15
+ // Copyright 2019-2022 @subwallet/extension-base
16
+ // SPDX-License-Identifier: Apache-2.0
17
+
18
+ class InterlayLendingPoolHandler extends _base.default {
19
+ altInputAsset = 'polkadot-NATIVE-DOT';
20
+ derivativeAssets = ['interlay-LOCAL-qDOT'];
21
+ inputAsset = 'interlay-LOCAL-DOT';
22
+ rewardAssets = ['interlay-LOCAL-DOT'];
23
+ feeAssets = ['interlay-NATIVE-INTR', 'interlay-LOCAL-DOT'];
24
+ constructor(state, chain) {
25
+ super(state, chain);
26
+ const chainInfo = this.chainInfo;
27
+ this.slug = `DOT___lending___${chain}`;
28
+ this.name = `${chainInfo.name} Lending`;
29
+ this.shortName = chainInfo.name.replaceAll(' Relay Chain', '');
30
+ }
31
+ getDescription() {
32
+ return 'Earn rewards by lending DOT';
33
+ }
34
+
35
+ /* Subscribe pool info */
36
+
37
+ async getPoolStat() {
38
+ const substrateApi = await this.substrateApi.isReady;
39
+ const inputTokenSlug = this.inputAsset;
40
+ const inputTokenInfo = this.state.getAssetBySlug(inputTokenSlug);
41
+ const _exchangeRate = await substrateApi.api.query.loans.exchangeRate((0, _utils._getTokenOnChainInfo)(inputTokenInfo));
42
+ const exchangeRate = _exchangeRate.toPrimitive();
43
+ const decimals = 10 ** 18;
44
+ return {
45
+ ...this.baseInfo,
46
+ type: this.type,
47
+ metadata: {
48
+ ...this.metadataInfo,
49
+ description: this.getDescription()
50
+ },
51
+ statistic: {
52
+ assetEarning: [{
53
+ slug: this.rewardAssets[0],
54
+ apr: 1.29,
55
+ exchangeRate: exchangeRate / decimals
56
+ }],
57
+ maxCandidatePerFarmer: 1,
58
+ maxWithdrawalRequestPerFarmer: 1,
59
+ minJoinPool: '10000000000',
60
+ minWithdrawal: '0',
61
+ totalApr: 1.29,
62
+ tvl: '291890000000000'
63
+ }
64
+ };
65
+ }
66
+
67
+ /* Subscribe pool info */
68
+
69
+ /* Subscribe pool position */
70
+
71
+ async subscribePoolPosition(useAddresses, resultCallback) {
72
+ let cancel = false;
73
+ const substrateApi = this.substrateApi;
74
+ await substrateApi.isReady;
75
+ const derivativeTokenSlug = this.derivativeAssets[0];
76
+ const derivativeTokenInfo = this.state.getAssetBySlug(derivativeTokenSlug);
77
+ const unsub = await substrateApi.api.query.tokens.accounts.multi(useAddresses.map(address => [address, (0, _utils._getTokenOnChainInfo)(derivativeTokenInfo)]), _balances => {
78
+ if (cancel) {
79
+ unsub();
80
+ return;
81
+ }
82
+ const balances = _balances;
83
+ for (let i = 0; i < balances.length; i++) {
84
+ const balanceItem = balances[i];
85
+ const address = useAddresses[i];
86
+ const bnTotalBalance = balanceItem.free || _util.BN_ZERO;
87
+ const totalBalance = bnTotalBalance.toString();
88
+ const result = {
89
+ ...this.baseInfo,
90
+ type: this.type,
91
+ address,
92
+ balanceToken: this.inputAsset,
93
+ totalStake: totalBalance,
94
+ activeStake: totalBalance,
95
+ unstakeBalance: '0',
96
+ status: _types.EarningStatus.EARNING_REWARD,
97
+ derivativeToken: derivativeTokenSlug,
98
+ isBondedBefore: bnTotalBalance.gt(_util.BN_ZERO),
99
+ nominations: [],
100
+ unstakings: []
101
+ };
102
+ resultCallback(result);
103
+ }
104
+ });
105
+ return () => {
106
+ cancel = true;
107
+ unsub();
108
+ };
109
+ }
110
+
111
+ /* Subscribe pool position */
112
+
113
+ /* Join pool action */
114
+
115
+ get submitJoinStepInfo() {
116
+ return {
117
+ name: 'Mint qDOT',
118
+ type: _types.YieldStepType.MINT_QDOT
119
+ };
120
+ }
121
+ async getSubmitStepFee(params) {
122
+ const poolOriginSubstrateApi = await this.substrateApi.isReady;
123
+ const inputTokenSlug = this.inputAsset;
124
+ const inputTokenInfo = this.state.getAssetBySlug(inputTokenSlug);
125
+ const defaultFeeTokenSlug = this.feeAssets[0];
126
+ if (new _util.BN(params.amount).gt(_util.BN_ZERO)) {
127
+ const _mintFeeInfo = await poolOriginSubstrateApi.api.tx.loans.mint((0, _utils._getTokenOnChainInfo)(inputTokenInfo), params.amount).paymentInfo(_constants.fakeAddress);
128
+ const mintFeeInfo = _mintFeeInfo.toPrimitive();
129
+ return {
130
+ amount: mintFeeInfo.partialFee.toString(),
131
+ slug: defaultFeeTokenSlug
132
+ };
133
+ } else {
134
+ return {
135
+ amount: '0',
136
+ slug: defaultFeeTokenSlug
137
+ };
138
+ }
139
+ }
140
+ async handleSubmitStep(data, path) {
141
+ const substrateApi = await this.substrateApi.isReady;
142
+ const inputTokenSlug = this.inputAsset;
143
+ const inputTokenInfo = this.state.getAssetBySlug(inputTokenSlug);
144
+ const extrinsic = substrateApi.api.tx.loans.mint((0, _utils._getTokenOnChainInfo)(inputTokenInfo), data.amount);
145
+ return {
146
+ txChain: this.chain,
147
+ extrinsicType: _KoniTypes.ExtrinsicType.MINT_QDOT,
148
+ extrinsic,
149
+ txData: data,
150
+ transferNativeAmount: '0'
151
+ };
152
+ }
153
+
154
+ /* Join pool action */
155
+
156
+ /* Leave pool action */
157
+
158
+ async handleYieldRedeem(amount, address, selectedTarget) {
159
+ const substrateApi = await this.substrateApi.isReady;
160
+ // @ts-ignore
161
+ const inputTokenSlug = this.inputAsset;
162
+ const inputTokenInfo = this.state.getAssetBySlug(inputTokenSlug);
163
+ const yieldPositionInfo = await this.getPoolPosition(address);
164
+ if (!yieldPositionInfo) {
165
+ return Promise.reject(new _TransactionError.TransactionError(_KoniTypes.BasicTxErrorType.INVALID_PARAMS));
166
+ }
167
+ const bnAmount = new _util.BN(amount);
168
+ const bnActiveBalance = new _util.BN(yieldPositionInfo.activeStake);
169
+ const redeemAll = bnAmount.eq(bnActiveBalance);
170
+ const extrinsic = !redeemAll ? substrateApi.api.tx.loans.redeem((0, _utils._getTokenOnChainInfo)(inputTokenInfo), amount) : substrateApi.api.tx.loans.redeemAll((0, _utils._getTokenOnChainInfo)(inputTokenInfo));
171
+ return [_KoniTypes.ExtrinsicType.REDEEM_QDOT, extrinsic];
172
+ }
173
+
174
+ /* Leave pool action */
175
+ }
176
+ exports.default = InterlayLendingPoolHandler;
@@ -0,0 +1,206 @@
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 _crossFetch = _interopRequireDefault(require("cross-fetch"));
13
+ var _util = require("@polkadot/util");
14
+ var _base = _interopRequireDefault(require("./base"));
15
+ // Copyright 2019-2022 @subwallet/extension-base
16
+ // SPDX-License-Identifier: Apache-2.0
17
+
18
+ const GRAPHQL_API = 'https://api.polkawallet.io/acala-liquid-staking-subql';
19
+ const EXCHANGE_RATE_REQUEST = 'query { dailySummaries(first:30, orderBy:TIMESTAMP_DESC) {nodes { exchangeRate timestamp }}}';
20
+ class AcalaLiquidStakingPoolHandler extends _base.default {
21
+ altInputAsset = 'polkadot-NATIVE-DOT';
22
+ derivativeAssets = ['acala-LOCAL-LDOT'];
23
+ inputAsset = 'acala-LOCAL-DOT';
24
+ rewardAssets = ['acala-LOCAL-DOT'];
25
+ feeAssets = ['acala-NATIVE-ACA', 'acala-LOCAL-DOT'];
26
+ /** @inner */
27
+ minAmountPercent = 0.98;
28
+ /** @inner */
29
+ allowDefaultUnstake = true;
30
+ constructor(state, chain) {
31
+ super(state, chain);
32
+ const chainInfo = this.chainInfo;
33
+ this.slug = `DOT___liquid_staking___${chain}`;
34
+ this.name = `${chainInfo.name} Liquid Staking`;
35
+ this.shortName = chainInfo.name.replaceAll(' Relay Chain', '');
36
+ }
37
+ getDescription() {
38
+ return 'Stake DOT to earn yield on LDOT';
39
+ }
40
+
41
+ /* Subscribe pool info */
42
+
43
+ async getPoolStat() {
44
+ const substrateApi = await this.substrateApi.isReady;
45
+ const stakingMetaPromise = new Promise(function (resolve) {
46
+ (0, _crossFetch.default)(GRAPHQL_API, {
47
+ method: 'POST',
48
+ headers: {
49
+ 'Content-Type': 'application/json'
50
+ },
51
+ body: JSON.stringify({
52
+ query: EXCHANGE_RATE_REQUEST
53
+ })
54
+ }).then(res => {
55
+ resolve(res.json());
56
+ }).catch(console.error);
57
+ });
58
+ const [_toBondPool, _totalStakingBonded, _stakingMeta] = await Promise.all([substrateApi.api.query.homa.toBondPool(), substrateApi.api.query.homa.totalStakingBonded(), stakingMetaPromise]);
59
+ const stakingMeta = _stakingMeta;
60
+ const stakingMetaList = stakingMeta.data.dailySummaries.nodes;
61
+ const latestExchangeRate = parseInt(stakingMetaList[0].exchangeRate);
62
+ const decimals = 10 ** 10;
63
+ const endingBalance = parseInt(stakingMetaList[0].exchangeRate);
64
+ const beginBalance = parseInt(stakingMetaList[29].exchangeRate);
65
+ const diff = endingBalance / beginBalance;
66
+ const apy = diff ** (365 / 30) - 1;
67
+ const toBondPool = new _util.BN(_toBondPool.toString());
68
+ const totalStakingBonded = new _util.BN(_totalStakingBonded.toString());
69
+ return {
70
+ ...this.baseInfo,
71
+ type: this.type,
72
+ metadata: {
73
+ ...this.metadataInfo,
74
+ description: this.getDescription()
75
+ },
76
+ statistic: {
77
+ assetEarning: [{
78
+ slug: this.rewardAssets[0],
79
+ apy: apy * 100,
80
+ exchangeRate: latestExchangeRate / decimals
81
+ }],
82
+ unstakingPeriod: 24 * 28,
83
+ maxCandidatePerFarmer: 1,
84
+ maxWithdrawalRequestPerFarmer: 1,
85
+ minJoinPool: '50000000000',
86
+ minWithdrawal: '50000000000',
87
+ totalApy: apy * 100,
88
+ tvl: totalStakingBonded.add(toBondPool).toString()
89
+ }
90
+ };
91
+ }
92
+
93
+ /* Subscribe pool info */
94
+
95
+ /* Subscribe pool position */
96
+
97
+ async subscribePoolPosition(useAddresses, resultCallback) {
98
+ let cancel = false;
99
+ const substrateApi = this.substrateApi;
100
+ await substrateApi.isReady;
101
+ const derivativeTokenSlug = this.derivativeAssets[0];
102
+ const derivativeTokenInfo = this.state.getAssetBySlug(derivativeTokenSlug);
103
+ const unsub = await substrateApi.api.query.tokens.accounts.multi(useAddresses.map(address => [address, (0, _utils._getTokenOnChainInfo)(derivativeTokenInfo)]), _balances => {
104
+ if (cancel) {
105
+ unsub();
106
+ return;
107
+ }
108
+ const balances = _balances;
109
+ for (let i = 0; i < balances.length; i++) {
110
+ const balanceItem = balances[i];
111
+ const address = useAddresses[i];
112
+ const bnTotalBalance = balanceItem.free || _util.BN_ZERO;
113
+ const totalBalance = bnTotalBalance.toString();
114
+ const result = {
115
+ ...this.baseInfo,
116
+ type: this.type,
117
+ address,
118
+ balanceToken: this.inputAsset,
119
+ totalStake: totalBalance,
120
+ activeStake: totalBalance,
121
+ unstakeBalance: '0',
122
+ status: _types.EarningStatus.EARNING_REWARD,
123
+ derivativeToken: derivativeTokenSlug,
124
+ isBondedBefore: bnTotalBalance.gt(_util.BN_ZERO),
125
+ nominations: [],
126
+ unstakings: []
127
+ };
128
+ resultCallback(result);
129
+ }
130
+ });
131
+ return () => {
132
+ cancel = true;
133
+ unsub();
134
+ };
135
+ }
136
+
137
+ /* Subscribe pool position */
138
+
139
+ /* Join pool action */
140
+
141
+ get submitJoinStepInfo() {
142
+ return {
143
+ name: 'Mint LDOT',
144
+ type: _types.YieldStepType.MINT_LDOT
145
+ };
146
+ }
147
+ async getSubmitStepFee(params) {
148
+ const poolOriginSubstrateApi = await this.substrateApi.isReady;
149
+ const defaultFeeTokenSlug = this.feeAssets[0];
150
+ if (new _util.BN(params.amount).gt(_util.BN_ZERO)) {
151
+ const _mintFeeInfo = await poolOriginSubstrateApi.api.tx.homa.mint(params.amount).paymentInfo(_constants.fakeAddress);
152
+ const mintFeeInfo = _mintFeeInfo.toPrimitive();
153
+ return {
154
+ amount: mintFeeInfo.partialFee.toString(),
155
+ slug: defaultFeeTokenSlug
156
+ };
157
+ } else {
158
+ return {
159
+ amount: '0',
160
+ slug: defaultFeeTokenSlug
161
+ };
162
+ }
163
+ }
164
+ async handleSubmitStep(data, path) {
165
+ const substrateApi = await this.substrateApi.isReady;
166
+ const extrinsic = substrateApi.api.tx.homa.mint(data.amount);
167
+ return {
168
+ txChain: this.chain,
169
+ extrinsicType: _KoniTypes.ExtrinsicType.MINT_LDOT,
170
+ extrinsic,
171
+ txData: data,
172
+ transferNativeAmount: '0'
173
+ };
174
+ }
175
+
176
+ /* Join pool action */
177
+
178
+ /* Leave pool action */
179
+
180
+ async handleYieldRedeem(amount, address, selectedTarget) {
181
+ const substrateApi = await this.substrateApi.isReady;
182
+ const weightedMinAmount = await this.createParamToRedeem(amount, address);
183
+ const extrinsic = substrateApi.api.tx.aggregatedDex.swapWithExactSupply(
184
+ // Swap path
185
+ [{
186
+ Taiga: [0, /* pool id */
187
+ 1, /* supply asset */
188
+ 0 /* target asset */]
189
+ }],
190
+ // Supply amount
191
+ amount,
192
+ // Min target amount
193
+ weightedMinAmount // should always set a min target to prevent unexpected result
194
+ );
195
+
196
+ return [_KoniTypes.ExtrinsicType.REDEEM_QDOT, extrinsic];
197
+ }
198
+ async handleYieldUnstake(amount, address, selectedTarget) {
199
+ const chainApi = await this.substrateApi.isReady;
200
+ const extrinsic = chainApi.api.tx.homa.requestRedeem(amount, false);
201
+ return [_KoniTypes.ExtrinsicType.UNSTAKE_QDOT, extrinsic];
202
+ }
203
+
204
+ /* Leave pool action */
205
+ }
206
+ exports.default = AcalaLiquidStakingPoolHandler;