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