@ledgerhq/live-common 25.2.0-next.0 → 25.2.0-next.1

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 (316) hide show
  1. package/lib/__tests__/test-helpers/setup.js +1 -0
  2. package/lib/__tests__/test-helpers/setup.js.map +1 -1
  3. package/lib/account/helpers.d.ts.map +1 -1
  4. package/lib/account/helpers.js +1 -0
  5. package/lib/account/helpers.js.map +1 -1
  6. package/lib/account/serialization.d.ts.map +1 -1
  7. package/lib/account/serialization.js +4 -0
  8. package/lib/account/serialization.js.map +1 -1
  9. package/lib/data/icons/react/index.d.ts +1 -0
  10. package/lib/data/icons/react/index.d.ts.map +1 -1
  11. package/lib/data/icons/react/index.js +7 -5
  12. package/lib/data/icons/react/index.js.map +1 -1
  13. package/lib/data/icons/react/osmo.d.ts +8 -0
  14. package/lib/data/icons/react/osmo.d.ts.map +1 -0
  15. package/lib/data/icons/react/osmo.js +39 -0
  16. package/lib/data/icons/react/osmo.js.map +1 -0
  17. package/lib/data/icons/reactNative/index.d.ts +1 -0
  18. package/lib/data/icons/reactNative/index.d.ts.map +1 -1
  19. package/lib/data/icons/reactNative/index.js +7 -5
  20. package/lib/data/icons/reactNative/index.js.map +1 -1
  21. package/lib/data/icons/reactNative/osmo.d.ts +8 -0
  22. package/lib/data/icons/reactNative/osmo.d.ts.map +1 -0
  23. package/lib/data/icons/reactNative/osmo.js +40 -0
  24. package/lib/data/icons/reactNative/osmo.js.map +1 -0
  25. package/lib/env.d.ts +15 -5
  26. package/lib/env.d.ts.map +1 -1
  27. package/lib/env.js +10 -0
  28. package/lib/env.js.map +1 -1
  29. package/lib/env.react.d.ts +1 -1
  30. package/lib/env.react.d.ts.map +1 -1
  31. package/lib/families/cosmos/CosmosValidatorsManager.d.ts +26 -0
  32. package/lib/families/cosmos/CosmosValidatorsManager.d.ts.map +1 -0
  33. package/lib/families/cosmos/CosmosValidatorsManager.js +365 -0
  34. package/lib/families/cosmos/CosmosValidatorsManager.js.map +1 -0
  35. package/lib/families/cosmos/account.d.ts +2 -2
  36. package/lib/families/cosmos/account.d.ts.map +1 -1
  37. package/lib/families/cosmos/account.js +19 -6
  38. package/lib/families/cosmos/account.js.map +1 -1
  39. package/lib/families/cosmos/api/Cosmos.d.ts +27 -15
  40. package/lib/families/cosmos/api/Cosmos.d.ts.map +1 -1
  41. package/lib/families/cosmos/api/Cosmos.js +418 -410
  42. package/lib/families/cosmos/api/Cosmos.js.map +1 -1
  43. package/lib/families/cosmos/bridge/js.d.ts.map +1 -1
  44. package/lib/families/cosmos/bridge/js.js +5 -5
  45. package/lib/families/cosmos/bridge/js.js.map +1 -1
  46. package/lib/families/cosmos/bridge/mock.js +1 -1
  47. package/lib/families/cosmos/bridge/mock.js.map +1 -1
  48. package/lib/families/cosmos/bridge.integration.test.js +5 -5
  49. package/lib/families/cosmos/bridge.integration.test.js.map +1 -1
  50. package/lib/families/cosmos/cli-transaction.d.ts +3 -3
  51. package/lib/families/cosmos/cli-transaction.d.ts.map +1 -1
  52. package/lib/families/cosmos/cli-transaction.js +4 -5
  53. package/lib/families/cosmos/cli-transaction.js.map +1 -1
  54. package/lib/families/cosmos/js-buildTransaction.js +3 -3
  55. package/lib/families/cosmos/js-buildTransaction.js.map +1 -1
  56. package/lib/families/cosmos/js-createTransaction.js +1 -1
  57. package/lib/families/cosmos/js-createTransaction.js.map +1 -1
  58. package/lib/families/cosmos/js-getTransactionStatus.d.ts +17 -3
  59. package/lib/families/cosmos/js-getTransactionStatus.d.ts.map +1 -1
  60. package/lib/families/cosmos/js-getTransactionStatus.js +224 -176
  61. package/lib/families/cosmos/js-getTransactionStatus.js.map +1 -1
  62. package/lib/families/cosmos/js-prepareTransaction.js +2 -2
  63. package/lib/families/cosmos/js-prepareTransaction.js.map +1 -1
  64. package/lib/families/cosmos/js-signOperation.js +3 -3
  65. package/lib/families/cosmos/js-signOperation.js.map +1 -1
  66. package/lib/families/cosmos/js-synchronisation.js +2 -2
  67. package/lib/families/cosmos/js-synchronisation.js.map +1 -1
  68. package/lib/families/cosmos/logic.js +1 -1
  69. package/lib/families/cosmos/logic.js.map +1 -1
  70. package/lib/families/cosmos/mock.js +1 -1
  71. package/lib/families/cosmos/mock.js.map +1 -1
  72. package/lib/families/cosmos/react.d.ts +4 -4
  73. package/lib/families/cosmos/react.d.ts.map +1 -1
  74. package/lib/families/cosmos/react.js +59 -26
  75. package/lib/families/cosmos/react.js.map +1 -1
  76. package/lib/families/cosmos/react.test.js +17 -15
  77. package/lib/families/cosmos/react.test.js.map +1 -1
  78. package/lib/families/cosmos/specs.js +2 -2
  79. package/lib/families/cosmos/specs.js.map +1 -1
  80. package/lib/families/cosmos/speculos-deviceActions.d.ts.map +1 -1
  81. package/lib/families/cosmos/speculos-deviceActions.js +1 -1
  82. package/lib/families/cosmos/speculos-deviceActions.js.map +1 -1
  83. package/lib/families/cosmos/transaction.d.ts +2 -2
  84. package/lib/families/cosmos/transaction.d.ts.map +1 -1
  85. package/lib/families/cosmos/transaction.js +4 -4
  86. package/lib/families/cosmos/transaction.js.map +1 -1
  87. package/lib/families/cosmos/types.d.ts +31 -13
  88. package/lib/families/cosmos/types.d.ts.map +1 -1
  89. package/lib/families/cosmos/utils.d.ts +1 -0
  90. package/lib/families/cosmos/utils.d.ts.map +1 -1
  91. package/lib/families/cosmos/utils.js +7 -1
  92. package/lib/families/cosmos/utils.js.map +1 -1
  93. package/lib/families/cosmos/validators.d.ts +3 -5
  94. package/lib/families/cosmos/validators.d.ts.map +1 -1
  95. package/lib/families/cosmos/validators.js +4 -317
  96. package/lib/families/cosmos/validators.js.map +1 -1
  97. package/lib/families/osmosis/OsmosisSupplyTypes.d.ts +48 -0
  98. package/lib/families/osmosis/OsmosisSupplyTypes.d.ts.map +1 -0
  99. package/lib/families/osmosis/OsmosisSupplyTypes.js +3 -0
  100. package/lib/families/osmosis/OsmosisSupplyTypes.js.map +1 -0
  101. package/lib/families/osmosis/account.d.ts +14 -0
  102. package/lib/families/osmosis/account.d.ts.map +1 -0
  103. package/lib/families/osmosis/account.js +60 -0
  104. package/lib/families/osmosis/account.js.map +1 -0
  105. package/lib/families/osmosis/api/sdk.d.ts +35 -0
  106. package/lib/families/osmosis/api/sdk.d.ts.map +1 -0
  107. package/lib/families/osmosis/api/sdk.js +478 -0
  108. package/lib/families/osmosis/api/sdk.js.map +1 -0
  109. package/lib/families/osmosis/api/sdk.types.d.ts +57 -0
  110. package/lib/families/osmosis/api/sdk.types.d.ts.map +1 -0
  111. package/lib/families/osmosis/api/sdk.types.js +15 -0
  112. package/lib/families/osmosis/api/sdk.types.js.map +1 -0
  113. package/lib/families/osmosis/api/sdk.unit.test.d.ts +2 -0
  114. package/lib/families/osmosis/api/sdk.unit.test.d.ts.map +1 -0
  115. package/lib/families/osmosis/api/sdk.unit.test.js +50 -0
  116. package/lib/families/osmosis/api/sdk.unit.test.js.map +1 -0
  117. package/lib/families/osmosis/bridge/js.d.ts +8 -0
  118. package/lib/families/osmosis/bridge/js.d.ts.map +1 -0
  119. package/lib/families/osmosis/bridge/js.js +98 -0
  120. package/lib/families/osmosis/bridge/js.js.map +1 -0
  121. package/lib/families/osmosis/bridge.integration.test.d.ts +2 -0
  122. package/lib/families/osmosis/bridge.integration.test.d.ts.map +1 -0
  123. package/lib/families/osmosis/bridge.integration.test.js +383 -0
  124. package/lib/families/osmosis/bridge.integration.test.js.map +1 -0
  125. package/lib/families/osmosis/cli-transaction.d.ts +38 -0
  126. package/lib/families/osmosis/cli-transaction.d.ts.map +1 -0
  127. package/lib/families/osmosis/cli-transaction.js +119 -0
  128. package/lib/families/osmosis/cli-transaction.js.map +1 -0
  129. package/lib/families/osmosis/deviceTransactionConfig.d.ts +25 -0
  130. package/lib/families/osmosis/deviceTransactionConfig.d.ts.map +1 -0
  131. package/lib/families/osmosis/deviceTransactionConfig.js +132 -0
  132. package/lib/families/osmosis/deviceTransactionConfig.js.map +1 -0
  133. package/lib/families/osmosis/errors.d.ts +4 -0
  134. package/lib/families/osmosis/errors.d.ts.map +1 -0
  135. package/lib/families/osmosis/errors.js +8 -0
  136. package/lib/families/osmosis/errors.js.map +1 -0
  137. package/lib/families/osmosis/hw-getAddress.d.ts +4 -0
  138. package/lib/families/osmosis/hw-getAddress.d.ts.map +1 -0
  139. package/lib/families/osmosis/hw-getAddress.js +64 -0
  140. package/lib/families/osmosis/hw-getAddress.js.map +1 -0
  141. package/lib/families/osmosis/js-buildTransaction.d.ts +14 -0
  142. package/lib/families/osmosis/js-buildTransaction.d.ts.map +1 -0
  143. package/lib/families/osmosis/js-buildTransaction.js +303 -0
  144. package/lib/families/osmosis/js-buildTransaction.js.map +1 -0
  145. package/lib/families/osmosis/js-estimateMaxSpendable.d.ts +15 -0
  146. package/lib/families/osmosis/js-estimateMaxSpendable.d.ts.map +1 -0
  147. package/lib/families/osmosis/js-estimateMaxSpendable.js +67 -0
  148. package/lib/families/osmosis/js-estimateMaxSpendable.js.map +1 -0
  149. package/lib/families/osmosis/js-getFeesForTransaction.d.ts +15 -0
  150. package/lib/families/osmosis/js-getFeesForTransaction.d.ts.map +1 -0
  151. package/lib/families/osmosis/js-getFeesForTransaction.js +85 -0
  152. package/lib/families/osmosis/js-getFeesForTransaction.js.map +1 -0
  153. package/lib/families/osmosis/js-getTransactionStatus.d.ts +3 -0
  154. package/lib/families/osmosis/js-getTransactionStatus.d.ts.map +1 -0
  155. package/lib/families/osmosis/js-getTransactionStatus.js +10 -0
  156. package/lib/families/osmosis/js-getTransactionStatus.js.map +1 -0
  157. package/lib/families/osmosis/js-signOperation.d.ts +10 -0
  158. package/lib/families/osmosis/js-signOperation.d.ts.map +1 -0
  159. package/lib/families/osmosis/js-signOperation.js +211 -0
  160. package/lib/families/osmosis/js-signOperation.js.map +1 -0
  161. package/lib/families/osmosis/js-synchronization.d.ts +9 -0
  162. package/lib/families/osmosis/js-synchronization.d.ts.map +1 -0
  163. package/lib/families/osmosis/js-synchronization.js +176 -0
  164. package/lib/families/osmosis/js-synchronization.js.map +1 -0
  165. package/lib/families/osmosis/js-transaction.d.ts +23 -0
  166. package/lib/families/osmosis/js-transaction.d.ts.map +1 -0
  167. package/lib/families/osmosis/js-transaction.js +177 -0
  168. package/lib/families/osmosis/js-transaction.js.map +1 -0
  169. package/lib/families/osmosis/logic.d.ts +5 -0
  170. package/lib/families/osmosis/logic.d.ts.map +1 -0
  171. package/lib/families/osmosis/logic.js +22 -0
  172. package/lib/families/osmosis/logic.js.map +1 -0
  173. package/lib/families/osmosis/preloadedData.d.ts +9 -0
  174. package/lib/families/osmosis/preloadedData.d.ts.map +1 -0
  175. package/lib/families/osmosis/preloadedData.js +32 -0
  176. package/lib/families/osmosis/preloadedData.js.map +1 -0
  177. package/lib/families/osmosis/serialization.d.ts +7 -0
  178. package/lib/families/osmosis/serialization.d.ts.map +1 -0
  179. package/lib/families/osmosis/serialization.js +5 -0
  180. package/lib/families/osmosis/serialization.js.map +1 -0
  181. package/lib/families/osmosis/specs.d.ts +7 -0
  182. package/lib/families/osmosis/specs.d.ts.map +1 -0
  183. package/lib/families/osmosis/specs.js +402 -0
  184. package/lib/families/osmosis/specs.js.map +1 -0
  185. package/lib/families/osmosis/speculos-deviceActions.d.ts +7 -0
  186. package/lib/families/osmosis/speculos-deviceActions.d.ts.map +1 -0
  187. package/lib/families/osmosis/speculos-deviceActions.js +120 -0
  188. package/lib/families/osmosis/speculos-deviceActions.js.map +1 -0
  189. package/lib/families/osmosis/transaction.d.ts +10 -0
  190. package/lib/families/osmosis/transaction.d.ts.map +1 -0
  191. package/lib/families/osmosis/transaction.js +13 -0
  192. package/lib/families/osmosis/transaction.js.map +1 -0
  193. package/lib/families/osmosis/types.d.ts +38 -0
  194. package/lib/families/osmosis/types.d.ts.map +1 -0
  195. package/lib/families/osmosis/types.js +3 -0
  196. package/lib/families/osmosis/types.js.map +1 -0
  197. package/lib/families/osmosis/utils.d.ts +8 -0
  198. package/lib/families/osmosis/utils.d.ts.map +1 -0
  199. package/lib/families/osmosis/utils.js +28 -0
  200. package/lib/families/osmosis/utils.js.map +1 -0
  201. package/lib/families/osmosis/validators.d.ts +4 -0
  202. package/lib/families/osmosis/validators.d.ts.map +1 -0
  203. package/lib/families/osmosis/validators.js +131 -0
  204. package/lib/families/osmosis/validators.js.map +1 -0
  205. package/lib/featureFlags/defaultFeatures.d.ts.map +1 -1
  206. package/lib/featureFlags/defaultFeatures.js +3 -0
  207. package/lib/featureFlags/defaultFeatures.js.map +1 -1
  208. package/lib/generated/account.d.ts +7 -1
  209. package/lib/generated/account.d.ts.map +1 -1
  210. package/lib/generated/account.js +4 -2
  211. package/lib/generated/account.js.map +1 -1
  212. package/lib/generated/bridge/js.d.ts +4 -0
  213. package/lib/generated/bridge/js.d.ts.map +1 -1
  214. package/lib/generated/bridge/js.js +14 -12
  215. package/lib/generated/bridge/js.js.map +1 -1
  216. package/lib/generated/cli-transaction.d.ts +33 -2
  217. package/lib/generated/cli-transaction.d.ts.map +1 -1
  218. package/lib/generated/cli-transaction.js +14 -12
  219. package/lib/generated/cli-transaction.js.map +1 -1
  220. package/lib/generated/deviceTransactionConfig.d.ts +4 -1
  221. package/lib/generated/deviceTransactionConfig.d.ts.map +1 -1
  222. package/lib/generated/deviceTransactionConfig.js +14 -12
  223. package/lib/generated/deviceTransactionConfig.js.map +1 -1
  224. package/lib/generated/hw-getAddress.d.ts +1 -0
  225. package/lib/generated/hw-getAddress.d.ts.map +1 -1
  226. package/lib/generated/hw-getAddress.js +14 -12
  227. package/lib/generated/hw-getAddress.js.map +1 -1
  228. package/lib/generated/specs.d.ts +3 -0
  229. package/lib/generated/specs.d.ts.map +1 -1
  230. package/lib/generated/specs.js +14 -12
  231. package/lib/generated/specs.js.map +1 -1
  232. package/lib/generated/speculos-deviceActions.d.ts +3 -0
  233. package/lib/generated/speculos-deviceActions.d.ts.map +1 -1
  234. package/lib/generated/speculos-deviceActions.js +14 -12
  235. package/lib/generated/speculos-deviceActions.js.map +1 -1
  236. package/lib/generated/transaction.d.ts +9 -1
  237. package/lib/generated/transaction.d.ts.map +1 -1
  238. package/lib/generated/transaction.js +14 -12
  239. package/lib/generated/transaction.js.map +1 -1
  240. package/lib/generated/types.d.ts +8 -4
  241. package/lib/generated/types.d.ts.map +1 -1
  242. package/lib/reconciliation.d.ts.map +1 -1
  243. package/lib/reconciliation.js +9 -0
  244. package/lib/reconciliation.js.map +1 -1
  245. package/package.json +8 -3
  246. package/src/__tests__/test-helpers/setup.ts +1 -0
  247. package/src/account/helpers.ts +1 -0
  248. package/src/account/serialization.ts +6 -0
  249. package/src/data/icons/react/index.tsx +1 -0
  250. package/src/data/icons/react/osmo.tsx +14 -0
  251. package/src/data/icons/reactNative/index.tsx +1 -0
  252. package/src/data/icons/reactNative/osmo.tsx +15 -0
  253. package/src/data/icons/svg/OSMO.svg +7 -0
  254. package/src/env.ts +10 -0
  255. package/src/families/cosmos/CosmosValidatorsManager.ts +420 -0
  256. package/src/families/cosmos/account.ts +29 -10
  257. package/src/families/cosmos/api/Cosmos.ts +267 -257
  258. package/src/families/cosmos/bridge/js.ts +6 -7
  259. package/src/families/cosmos/bridge/mock.ts +1 -1
  260. package/src/families/cosmos/bridge.integration.test.ts +5 -5
  261. package/src/families/cosmos/cli-transaction.ts +7 -8
  262. package/src/families/cosmos/js-buildTransaction.ts +4 -4
  263. package/src/families/cosmos/js-createTransaction.ts +1 -1
  264. package/src/families/cosmos/js-getTransactionStatus.ts +276 -226
  265. package/src/families/cosmos/js-prepareTransaction.ts +3 -3
  266. package/src/families/cosmos/js-signOperation.ts +4 -4
  267. package/src/families/cosmos/js-synchronisation.ts +3 -3
  268. package/src/families/cosmos/logic.ts +1 -1
  269. package/src/families/cosmos/mock.ts +1 -1
  270. package/src/families/cosmos/react.test.ts +25 -14
  271. package/src/families/cosmos/react.ts +73 -21
  272. package/src/families/cosmos/specs.ts +2 -2
  273. package/src/families/cosmos/speculos-deviceActions.ts +1 -2
  274. package/src/families/cosmos/transaction.ts +4 -6
  275. package/src/families/cosmos/types.ts +41 -13
  276. package/src/families/cosmos/utils.ts +8 -0
  277. package/src/families/cosmos/validators.ts +5 -363
  278. package/src/families/osmosis/OsmosisSupplyTypes.ts +53 -0
  279. package/src/families/osmosis/__snapshots__/bridge.integration.test.ts.snap +852 -0
  280. package/src/families/osmosis/account.ts +65 -0
  281. package/src/families/osmosis/api/sdk.ts +530 -0
  282. package/src/families/osmosis/api/sdk.types.ts +65 -0
  283. package/src/families/osmosis/api/sdk.unit.test.ts +70 -0
  284. package/src/families/osmosis/bridge/js.ts +64 -0
  285. package/src/families/osmosis/bridge.integration.test.ts +467 -0
  286. package/src/families/osmosis/cli-transaction.ts +145 -0
  287. package/src/families/osmosis/deviceTransactionConfig.ts +174 -0
  288. package/src/families/osmosis/errors.ts +13 -0
  289. package/src/families/osmosis/hw-getAddress.ts +14 -0
  290. package/src/families/osmosis/js-buildTransaction.ts +306 -0
  291. package/src/families/osmosis/js-estimateMaxSpendable.ts +26 -0
  292. package/src/families/osmosis/js-getFeesForTransaction.ts +44 -0
  293. package/src/families/osmosis/js-getTransactionStatus.ts +9 -0
  294. package/src/families/osmosis/js-signOperation.ts +172 -0
  295. package/src/families/osmosis/js-synchronization.ts +122 -0
  296. package/src/families/osmosis/js-transaction.ts +96 -0
  297. package/src/families/osmosis/logic.ts +26 -0
  298. package/src/families/osmosis/preloadedData.ts +32 -0
  299. package/src/families/osmosis/serialization.ts +6 -0
  300. package/src/families/osmosis/specs.ts +393 -0
  301. package/src/families/osmosis/speculos-deviceActions.ts +94 -0
  302. package/src/families/osmosis/transaction.ts +20 -0
  303. package/src/families/osmosis/types.ts +48 -0
  304. package/src/families/osmosis/utils.ts +31 -0
  305. package/src/families/osmosis/validators.ts +79 -0
  306. package/src/featureFlags/defaultFeatures.ts +3 -0
  307. package/src/generated/account.ts +3 -0
  308. package/src/generated/bridge/js.ts +3 -0
  309. package/src/generated/cli-transaction.ts +3 -0
  310. package/src/generated/deviceTransactionConfig.ts +5 -0
  311. package/src/generated/hw-getAddress.ts +3 -0
  312. package/src/generated/specs.ts +3 -0
  313. package/src/generated/speculos-deviceActions.ts +3 -0
  314. package/src/generated/transaction.ts +3 -0
  315. package/src/generated/types.ts +8 -0
  316. package/src/reconciliation.ts +16 -0
@@ -3,9 +3,15 @@ import { BigNumber } from "bignumber.js";
3
3
  import { getCurrentCosmosPreloadData } from "./preloadedData";
4
4
  import { getAccountUnit } from "../../account";
5
5
  import { formatCurrencyUnit } from "../../currencies";
6
- import { CosmosOperation, CosmosExtraTxInfo, CosmosAccount } from "./types";
6
+ import {
7
+ CosmosOperation,
8
+ CosmosExtraTxInfo,
9
+ CosmosPreloadData,
10
+ CosmosAccount,
11
+ } from "./types";
7
12
  import { mapDelegations, mapUnbondings, mapRedelegations } from "./logic";
8
- import { Unit } from "@ledgerhq/types-cryptoassets";
13
+ import { getCurrentOsmosisPreloadData } from "../osmosis/preloadedData";
14
+ import type { Unit } from "@ledgerhq/types-cryptoassets";
9
15
 
10
16
  function formatOperationSpecifics(
11
17
  op: CosmosOperation,
@@ -27,10 +33,22 @@ function formatOperationSpecifics(
27
33
  .join("");
28
34
  }
29
35
 
30
- function formatAccountSpecifics(account: CosmosAccount): string {
36
+ function getCurrentCosmosFamilyPreloadData(
37
+ currencyName: string
38
+ ): CosmosPreloadData {
39
+ if (currencyName === "osmosis") {
40
+ return getCurrentOsmosisPreloadData();
41
+ } else {
42
+ return getCurrentCosmosPreloadData();
43
+ }
44
+ }
45
+
46
+ export function formatAccountSpecifics(account: CosmosAccount): string {
31
47
  const { cosmosResources } = account;
32
48
  invariant(cosmosResources, "cosmos account expected");
33
- const { validators } = getCurrentCosmosPreloadData();
49
+ const currencyName = account.currency.name.toLowerCase();
50
+ const { validators } = getCurrentCosmosFamilyPreloadData(currencyName);
51
+
34
52
  const unit = getAccountUnit(account);
35
53
  const formatConfig = {
36
54
  disableRounding: true,
@@ -127,8 +145,9 @@ function formatAccountSpecifics(account: CosmosAccount): string {
127
145
  export function fromOperationExtraRaw(
128
146
  extra: Record<string, any> | null | undefined
129
147
  ): CosmosExtraTxInfo | Record<string, any> | null | undefined {
148
+ let e = {};
130
149
  if (extra && extra.validators) {
131
- return {
150
+ e = {
132
151
  ...extra,
133
152
  validators: extra.validators.map((o) => ({
134
153
  ...o,
@@ -136,14 +155,15 @@ export function fromOperationExtraRaw(
136
155
  })),
137
156
  };
138
157
  }
139
-
140
- return extra;
158
+ return e;
141
159
  }
142
160
  export function toOperationExtraRaw(
143
161
  extra: Record<string, any> | null | undefined
144
162
  ): CosmosExtraTxInfo | Record<string, any> | null | undefined {
163
+ let e = {};
164
+
145
165
  if (extra && extra.validators) {
146
- return {
166
+ e = {
147
167
  ...extra,
148
168
  validators: extra.validators.map((o) => ({
149
169
  ...o,
@@ -151,8 +171,7 @@ export function toOperationExtraRaw(
151
171
  })),
152
172
  };
153
173
  }
154
-
155
- return extra;
174
+ return e;
156
175
  }
157
176
  export default {
158
177
  formatAccountSpecifics,
@@ -9,297 +9,307 @@ const defaultEndpoint = getEnv(
9
9
  "API_COSMOS_BLOCKCHAIN_EXPLORER_API_ENDPOINT"
10
10
  ).replace(/\/$/, "");
11
11
 
12
- export const getAccountInfo = async (
13
- address: string,
14
- currency: CryptoCurrency
15
- ): Promise<any> => {
16
- try {
17
- const [
18
- { accountNumber, sequence },
19
- balances,
20
- blockHeight,
21
- txs,
22
- delegations,
23
- redelegations,
24
- unbondings,
25
- withdrawAddress,
26
- ] = await Promise.all([
27
- getAccount(address),
28
- getAllBalances(address, currency),
29
- getHeight(),
30
- getTransactions(address),
31
- getDelegations(address, currency),
32
- getRedelegations(address),
33
- getUnbondings(address),
34
- getWithdrawAddress(address),
35
- ]);
36
-
37
- return {
38
- balances,
39
- blockHeight,
40
- txs,
41
- delegations,
42
- redelegations,
43
- unbondings,
44
- withdrawAddress,
45
- accountNumber,
46
- sequence,
12
+ export class CosmosAPI {
13
+ protected _defaultEndpoint: string = defaultEndpoint;
14
+ protected _namespace = "cosmos";
15
+
16
+ getAccountInfo = async (
17
+ address: string,
18
+ currency: CryptoCurrency
19
+ ): Promise<any> => {
20
+ try {
21
+ const [
22
+ { accountNumber, sequence },
23
+ balances,
24
+ blockHeight,
25
+ txs,
26
+ delegations,
27
+ redelegations,
28
+ unbondings,
29
+ withdrawAddress,
30
+ ] = await Promise.all([
31
+ this.getAccount(address),
32
+ this.getAllBalances(address, currency),
33
+ this.getHeight(),
34
+ this.getTransactions(address),
35
+ this.getDelegations(address, currency),
36
+ this.getRedelegations(address),
37
+ this.getUnbondings(address),
38
+ this.getWithdrawAddress(address),
39
+ ]);
40
+
41
+ return {
42
+ balances,
43
+ blockHeight,
44
+ txs,
45
+ delegations,
46
+ redelegations,
47
+ unbondings,
48
+ withdrawAddress,
49
+ accountNumber,
50
+ sequence,
51
+ };
52
+ } catch (e: any) {
53
+ throw new Error(`"Error during cosmos synchronization: "${e.message}`);
54
+ }
55
+ };
56
+
57
+ getAccount = async (
58
+ address: string
59
+ ): Promise<{ address: string; accountNumber: number; sequence: number }> => {
60
+ const response = {
61
+ address: address,
62
+ accountNumber: 0,
63
+ sequence: 0,
47
64
  };
48
- } catch (e: any) {
49
- throw new Error(`"Error during cosmos synchronization: "${e.message}`);
50
- }
51
- };
52
-
53
- export const getAccount = async (
54
- address: string
55
- ): Promise<{ address: string; accountNumber: number; sequence: number }> => {
56
- const response = {
57
- address: address,
58
- accountNumber: 0,
59
- sequence: 0,
65
+
66
+ try {
67
+ const { data } = await network({
68
+ method: "GET",
69
+ url: `${this._defaultEndpoint}/cosmos/auth/v1beta1/accounts/${address}`,
70
+ });
71
+
72
+ if (data.account.address) {
73
+ response.address = data.account.address;
74
+ }
75
+
76
+ if (data.account.account_number) {
77
+ response.accountNumber = parseInt(data.account.account_number);
78
+ }
79
+
80
+ if (data.account.sequence) {
81
+ response.sequence = parseInt(data.account.sequence);
82
+ }
83
+ // eslint-disable-next-line no-empty
84
+ } catch (e) {}
85
+ return response;
60
86
  };
61
87
 
62
- try {
88
+ getChainId = async (): Promise<string> => {
63
89
  const { data } = await network({
64
90
  method: "GET",
65
- url: `${defaultEndpoint}/cosmos/auth/v1beta1/accounts/${address}`,
91
+ url: `${this._defaultEndpoint}/node_info`,
66
92
  });
67
93
 
68
- if (data.account.address) {
69
- response.address = data.account.address;
70
- }
94
+ return data.node_info.network;
95
+ };
71
96
 
72
- if (data.account.account_number) {
73
- response.accountNumber = parseInt(data.account.account_number);
74
- }
97
+ getHeight = async (): Promise<number> => {
98
+ const { data } = await network({
99
+ method: "GET",
100
+ url: `${this._defaultEndpoint}/cosmos/base/tendermint/v1beta1/blocks/latest`,
101
+ });
102
+
103
+ return data.block.header.height;
104
+ };
75
105
 
76
- if (data.account.sequence) {
77
- response.sequence = parseInt(data.account.sequence);
106
+ getAllBalances = async (
107
+ address: string,
108
+ currency: CryptoCurrency
109
+ ): Promise<BigNumber> => {
110
+ const { data } = await network({
111
+ method: "GET",
112
+ url: `${this._defaultEndpoint}/cosmos/bank/v1beta1/balances/${address}`,
113
+ });
114
+
115
+ let amount = new BigNumber(0);
116
+
117
+ for (const elem of data.balances) {
118
+ if (elem.denom === currency.units[1].code)
119
+ amount = amount.plus(elem.amount);
78
120
  }
79
- // eslint-disable-next-line no-empty
80
- } catch (e) {}
81
- return response;
82
- };
83
-
84
- export const getChainId = async (): Promise<string> => {
85
- const { data } = await network({
86
- method: "GET",
87
- url: `${defaultEndpoint}/node_info`,
88
- });
89
-
90
- return data.node_info.network;
91
- };
92
-
93
- const getHeight = async (): Promise<number> => {
94
- const { data } = await network({
95
- method: "GET",
96
- url: `${defaultEndpoint}/cosmos/base/tendermint/v1beta1/blocks/latest`,
97
- });
98
-
99
- return data.block.header.height;
100
- };
101
-
102
- const getAllBalances = async (
103
- address: string,
104
- currency: CryptoCurrency
105
- ): Promise<BigNumber> => {
106
- const { data } = await network({
107
- method: "GET",
108
- url: `${defaultEndpoint}/cosmos/bank/v1beta1/balances/${address}`,
109
- });
110
-
111
- let amount = new BigNumber(0);
112
-
113
- for (const elem of data.balances) {
114
- if (elem.denom === currency.units[1].code)
115
- amount = amount.plus(elem.amount);
116
- }
117
-
118
- return amount;
119
- };
120
-
121
- const getDelegations = async (
122
- address: string,
123
- currency: CryptoCurrency
124
- ): Promise<any> => {
125
- const delegations: Array<any> = [];
126
-
127
- const { data: data1 } = await network({
128
- method: "GET",
129
- url: `${defaultEndpoint}/cosmos/staking/v1beta1/delegations/${address}`,
130
- });
131
-
132
- data1.delegation_responses = data1.delegation_responses.filter(
133
- (d) => d.balance.amount !== "0"
134
- );
135
-
136
- let status = "unbonded";
137
- const statusMap = {
138
- BOND_STATUS_UNBONDED: "unbonded",
139
- BOND_STATUS_UNBONDING: "unbonding",
140
- BOND_STATUS_BONDED: "bonded",
121
+
122
+ return amount;
141
123
  };
142
124
 
143
- for (const d of data1.delegation_responses) {
144
- const { data: data2 } = await network({
125
+ getDelegations = async (
126
+ address: string,
127
+ currency: CryptoCurrency
128
+ ): Promise<any> => {
129
+ const delegations: Array<any> = [];
130
+
131
+ const { data: data1 } = await network({
145
132
  method: "GET",
146
- url: `${defaultEndpoint}/cosmos/staking/v1beta1/validators/${d.delegation.validator_address}`,
133
+ url: `${this._defaultEndpoint}/cosmos/staking/v1beta1/delegations/${address}`,
147
134
  });
148
135
 
149
- status = statusMap[data2.validator.status] || "unbonded";
136
+ data1.delegation_responses = data1.delegation_responses.filter(
137
+ (d) => d.balance.amount !== "0"
138
+ );
139
+
140
+ let status = "unbonded";
141
+ const statusMap = {
142
+ BOND_STATUS_UNBONDED: "unbonded",
143
+ BOND_STATUS_UNBONDING: "unbonding",
144
+ BOND_STATUS_BONDED: "bonded",
145
+ };
146
+
147
+ for (const d of data1.delegation_responses) {
148
+ const { data: data2 } = await network({
149
+ method: "GET",
150
+ url: `${this._defaultEndpoint}/cosmos/staking/v1beta1/validators/${d.delegation.validator_address}`,
151
+ });
152
+
153
+ status = statusMap[data2.validator.status] || "unbonded";
150
154
 
151
- delegations.push({
152
- validatorAddress: d.delegation.validator_address,
153
- amount:
154
- d.balance.denom === currency.units[1].code
155
- ? new BigNumber(d.balance.amount)
156
- : new BigNumber(0),
157
- pendingRewards: new BigNumber(0),
158
- status,
155
+ delegations.push({
156
+ validatorAddress: d.delegation.validator_address,
157
+ amount:
158
+ d.balance.denom === currency.units[1].code
159
+ ? new BigNumber(d.balance.amount)
160
+ : new BigNumber(0),
161
+ pendingRewards: new BigNumber(0),
162
+ status,
163
+ });
164
+ }
165
+
166
+ const { data: data3 } = await network({
167
+ method: "GET",
168
+ url: `${this._defaultEndpoint}/cosmos/distribution/v1beta1/delegators/${address}/rewards`,
159
169
  });
160
- }
161
-
162
- const { data: data3 } = await network({
163
- method: "GET",
164
- url: `${defaultEndpoint}/cosmos/distribution/v1beta1/delegators/${address}/rewards`,
165
- });
166
-
167
- for (const r of data3.rewards) {
168
- for (const d of delegations) {
169
- if (r.validator_address === d.validatorAddress) {
170
- for (const reward of r.reward) {
171
- d.pendingRewards = d.pendingRewards.plus(
172
- new BigNumber(reward.amount).integerValue()
173
- );
170
+
171
+ for (const r of data3.rewards) {
172
+ for (const d of delegations) {
173
+ if (r.validator_address === d.validatorAddress) {
174
+ for (const reward of r.reward) {
175
+ d.pendingRewards = d.pendingRewards.plus(
176
+ new BigNumber(reward.amount).integerValue()
177
+ );
178
+ }
174
179
  }
175
180
  }
176
181
  }
177
- }
178
-
179
- return delegations;
180
- };
181
-
182
- const getRedelegations = async (address: string): Promise<any> => {
183
- const redelegations: Array<any> = [];
184
-
185
- const { data } = await network({
186
- method: "GET",
187
- url: `${defaultEndpoint}/cosmos/staking/v1beta1/delegators/${address}/redelegations`,
188
- });
189
-
190
- for (const r of data.redelegation_responses) {
191
- for (const entry of r.entries) {
192
- redelegations.push({
193
- validatorSrcAddress: r.redelegation.validator_src_address,
194
- validatorDstAddress: r.redelegation.validator_dst_address,
195
- amount: new BigNumber(entry.redelegation_entry.initial_balance),
196
- completionDate: new Date(entry.redelegation_entry.completion_time),
197
- });
182
+
183
+ return delegations;
184
+ };
185
+
186
+ getRedelegations = async (address: string): Promise<any> => {
187
+ const redelegations: Array<any> = [];
188
+
189
+ const { data } = await network({
190
+ method: "GET",
191
+ url: `${this._defaultEndpoint}/cosmos/staking/v1beta1/delegators/${address}/redelegations`,
192
+ });
193
+
194
+ for (const r of data.redelegation_responses) {
195
+ for (const entry of r.entries) {
196
+ redelegations.push({
197
+ validatorSrcAddress: r.redelegation.validator_src_address,
198
+ validatorDstAddress: r.redelegation.validator_dst_address,
199
+ amount: new BigNumber(entry.redelegation_entry.initial_balance),
200
+ completionDate: new Date(entry.redelegation_entry.completion_time),
201
+ });
202
+ }
198
203
  }
199
- }
200
204
 
201
- return redelegations;
202
- };
205
+ return redelegations;
206
+ };
207
+
208
+ getUnbondings = async (address: string): Promise<any> => {
209
+ const unbondings: Array<any> = [];
210
+
211
+ const { data } = await network({
212
+ method: "GET",
213
+ url: `${this._defaultEndpoint}/cosmos/staking/v1beta1/delegators/${address}/unbonding_delegations`,
214
+ });
215
+
216
+ for (const u of data.unbonding_responses) {
217
+ for (const entry of u.entries) {
218
+ unbondings.push({
219
+ validatorAddress: u.validator_address,
220
+ amount: new BigNumber(entry.initial_balance),
221
+ completionDate: new Date(entry.completion_time),
222
+ });
223
+ }
224
+ }
203
225
 
204
- const getUnbondings = async (address: string): Promise<any> => {
205
- const unbondings: Array<any> = [];
226
+ return unbondings;
227
+ };
206
228
 
207
- const { data } = await network({
208
- method: "GET",
209
- url: `${defaultEndpoint}/cosmos/staking/v1beta1/delegators/${address}/unbonding_delegations`,
210
- });
229
+ getWithdrawAddress = async (address: string): Promise<string> => {
230
+ const { data } = await network({
231
+ method: "GET",
232
+ url: `${this._defaultEndpoint}/cosmos/distribution/v1beta1/delegators/${address}/withdraw_address`,
233
+ });
211
234
 
212
- for (const u of data.unbonding_responses) {
213
- for (const entry of u.entries) {
214
- unbondings.push({
215
- validatorAddress: u.validator_address,
216
- amount: new BigNumber(entry.initial_balance),
217
- completionDate: new Date(entry.completion_time),
218
- });
235
+ return data.withdraw_address;
236
+ };
237
+
238
+ getTransactions = async (address: string): Promise<any> => {
239
+ if (this._namespace === "osmosis") {
240
+ return [];
219
241
  }
220
- }
221
-
222
- return unbondings;
223
- };
224
-
225
- const getWithdrawAddress = async (address: string): Promise<string> => {
226
- const { data } = await network({
227
- method: "GET",
228
- url: `${defaultEndpoint}/cosmos/distribution/v1beta1/delegators/${address}/withdraw_address`,
229
- });
230
-
231
- return data.withdraw_address;
232
- };
233
-
234
- const getTransactions = async (address: string): Promise<any> => {
235
- const receive = await network({
236
- method: "GET",
237
- url:
238
- `${defaultEndpoint}/cosmos/tx/v1beta1/txs?events=` +
239
- encodeURI(`transfer.recipient='${address}'`),
240
- });
241
-
242
- const send = await network({
243
- method: "GET",
244
- url:
245
- `${defaultEndpoint}/cosmos/tx/v1beta1/txs?events=` +
246
- encodeURI(`message.sender='${address}'`),
247
- });
248
-
249
- return [...receive.data.tx_responses, ...send.data.tx_responses];
250
- };
251
-
252
- export const isValidRecipent = async (address: string): Promise<boolean> => {
253
- try {
254
- await network({
242
+ const receive = await network({
243
+ method: "GET",
244
+ url:
245
+ `${this._defaultEndpoint}/cosmos/tx/v1beta1/txs?events=` +
246
+ encodeURI(`transfer.recipient='${address}'`),
247
+ });
248
+
249
+ const send = await network({
255
250
  method: "GET",
256
- url: `${defaultEndpoint}/cosmos/bank/v1beta1/balances/${address}`,
251
+ url:
252
+ `${this._defaultEndpoint}/cosmos/tx/v1beta1/txs?events=` +
253
+ encodeURI(`message.sender='${address}'`),
257
254
  });
258
255
 
259
- return true;
260
- } catch (e) {
261
- return false;
262
- }
263
- };
256
+ return [...receive.data.tx_responses, ...send.data.tx_responses];
257
+ };
258
+
259
+ isValidRecipent = async (address: string): Promise<boolean> => {
260
+ try {
261
+ await network({
262
+ method: "GET",
263
+ url: `${this._defaultEndpoint}/cosmos/bank/v1beta1/balances/${address}`,
264
+ });
265
+
266
+ return true;
267
+ } catch (e) {
268
+ return false;
269
+ }
270
+ };
271
+
272
+ simulate = async (tx_bytes: Array<any>): Promise<BigNumber> => {
273
+ try {
274
+ const { data } = await network({
275
+ method: "POST",
276
+ url: `${this._defaultEndpoint}/cosmos/tx/v1beta1/simulate`,
277
+ data: {
278
+ tx_bytes: tx_bytes,
279
+ },
280
+ });
281
+
282
+ return new BigNumber(data?.gas_info?.gas_used || 0);
283
+ } catch (e) {
284
+ return new BigNumber(0);
285
+ }
286
+ };
264
287
 
265
- export const simulate = async (tx_bytes: Array<any>): Promise<BigNumber> => {
266
- try {
288
+ broadcast = async ({
289
+ signedOperation: { operation, signature },
290
+ }): Promise<Operation> => {
267
291
  const { data } = await network({
268
292
  method: "POST",
269
- url: `${defaultEndpoint}/cosmos/tx/v1beta1/simulate`,
293
+ url: `${this._defaultEndpoint}/cosmos/tx/v1beta1/txs`,
270
294
  data: {
271
- tx_bytes: tx_bytes,
295
+ tx_bytes: Array.from(Uint8Array.from(Buffer.from(signature, "hex"))),
296
+ mode: "BROADCAST_MODE_SYNC",
272
297
  },
273
298
  });
274
299
 
275
- return new BigNumber(data?.gas_info?.gas_used || 0);
276
- } catch (e) {
277
- return new BigNumber(0);
278
- }
279
- };
280
-
281
- export const broadcast = async ({
282
- signedOperation: { operation, signature },
283
- }): Promise<Operation> => {
284
- const { data } = await network({
285
- method: "POST",
286
- url: `${defaultEndpoint}/cosmos/tx/v1beta1/txs`,
287
- data: {
288
- tx_bytes: Array.from(Uint8Array.from(Buffer.from(signature, "hex"))),
289
- mode: "BROADCAST_MODE_SYNC",
290
- },
291
- });
292
-
293
- if (data.tx_response.code != 0) {
294
- // error codes: https://github.com/cosmos/cosmos-sdk/blob/master/types/errors/errors.go
295
- throw new Error(
296
- "invalid broadcast return (code: " +
297
- (data.tx_response.code || "?") +
298
- ", message: '" +
299
- (data.tx_response.raw_log || "") +
300
- "')"
301
- );
302
- }
300
+ if (data.tx_response.code != 0) {
301
+ // error codes: https://github.com/cosmos/cosmos-sdk/blob/master/types/errors/errors.go
302
+ throw new Error(
303
+ "invalid broadcast return (code: " +
304
+ (data.tx_response.code || "?") +
305
+ ", message: '" +
306
+ (data.tx_response.raw_log || "") +
307
+ "')"
308
+ );
309
+ }
310
+
311
+ return patchOperationWithHash(operation, data.tx_response.txhash);
312
+ };
313
+ }
303
314
 
304
- return patchOperationWithHash(operation, data.tx_response.txhash);
305
- };
315
+ export const defaultCosmosAPI = new CosmosAPI();