@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
@@ -0,0 +1,393 @@
1
+ import invariant from "invariant";
2
+ import type { Transaction } from "./types";
3
+ import { getCryptoCurrencyById, parseCurrencyUnit } from "../../currencies";
4
+ import { pickSiblings } from "../../bot/specs";
5
+ import type { AppSpec } from "../../bot/types";
6
+ import { DeviceModelId } from "@ledgerhq/devices";
7
+ import type {
8
+ CosmosAccount,
9
+ CosmosDelegation,
10
+ CosmosRedelegation,
11
+ CosmosResources,
12
+ CosmosUnbonding,
13
+ } from "../cosmos/types";
14
+ import { canClaimRewards, canUndelegate, canRedelegate } from "../cosmos/logic";
15
+ import { canDelegate, getMaxDelegationAvailable } from "./logic";
16
+ import { getCurrentOsmosisPreloadData } from "../osmosis/preloadedData";
17
+ import sampleSize from "lodash/sampleSize";
18
+ import sample from "lodash/sample";
19
+ import expect from "expect";
20
+ import { toOperationRaw } from "../../account";
21
+ import { BigNumber } from "bignumber.js";
22
+
23
+ const currency = getCryptoCurrencyById("osmosis");
24
+ const minimalAmount = parseCurrencyUnit(currency.units[0], "0.00001");
25
+ const maxAccount = 3;
26
+ // amounts of delegation are not exact so we are applying an approximation
27
+ function approximateValue(value) {
28
+ return "~" + value.div(100).integerValue().times(100).toString();
29
+ }
30
+
31
+ function approximateExtra(extra) {
32
+ extra = { ...extra };
33
+ if (extra.validators && Array.isArray(extra.validators)) {
34
+ extra.validators = extra.validators.map((v) => {
35
+ if (!v) return v;
36
+ const { amount, ...rest } = v;
37
+ if (!amount || typeof amount !== "string") return v;
38
+ return { ...rest, amount: approximateValue(new BigNumber(amount)) };
39
+ });
40
+ }
41
+ return extra;
42
+ }
43
+
44
+ const osmosis: AppSpec<Transaction> = {
45
+ name: "Osmosis",
46
+ currency: getCryptoCurrencyById("osmosis"),
47
+ appQuery: {
48
+ model: DeviceModelId.nanoS,
49
+ appName: "Cosmos",
50
+ },
51
+ testTimeout: 2 * 60 * 1000,
52
+ transactionCheck: ({ maxSpendable }) => {
53
+ invariant(maxSpendable.gt(minimalAmount), "balance is too low");
54
+ },
55
+ test: ({ account, operation, optimisticOperation }) => {
56
+ const allOperationsMatchingId = account.operations.filter(
57
+ (op) => op.id === operation.id
58
+ );
59
+ if (allOperationsMatchingId.length > 1) {
60
+ console.warn(allOperationsMatchingId);
61
+ }
62
+ expect({ allOperationsMatchingId }).toEqual({
63
+ allOperationsMatchingId: [operation],
64
+ });
65
+ const opExpected: Record<string, any> = toOperationRaw({
66
+ ...optimisticOperation,
67
+ });
68
+ delete opExpected.value;
69
+ delete opExpected.fee;
70
+ delete opExpected.date;
71
+ delete opExpected.blockHash;
72
+ delete opExpected.blockHeight;
73
+ const extra = opExpected.extra;
74
+ delete opExpected.extra;
75
+ delete opExpected.transactionSequenceNumber;
76
+ const op = toOperationRaw(operation);
77
+ expect(op).toMatchObject(opExpected);
78
+ expect(approximateExtra(op.extra)).toMatchObject(approximateExtra(extra));
79
+ },
80
+ mutations: [
81
+ {
82
+ name: "move 50% to another account",
83
+ maxRun: 2,
84
+ transaction: ({ account, siblings, bridge, maxSpendable }) => {
85
+ invariant(maxSpendable.gt(minimalAmount), "balance is too low");
86
+ const sibling = pickSiblings(siblings, maxAccount);
87
+ const recipient = sibling.freshAddress;
88
+ const amount = maxSpendable.div(2).integerValue();
89
+ return {
90
+ transaction: bridge.createTransaction(account),
91
+ updates: [
92
+ { recipient },
93
+ { amount },
94
+ Math.random() < 0.5
95
+ ? {
96
+ memo: "LedgerLiveBot",
97
+ }
98
+ : null,
99
+ ],
100
+ };
101
+ },
102
+ },
103
+ {
104
+ name: "send max to another account",
105
+ maxRun: 1,
106
+ transaction: ({ account, siblings, bridge, maxSpendable }) => {
107
+ invariant(maxSpendable.gt(minimalAmount), "balance is too low");
108
+ const sibling = pickSiblings(siblings, maxAccount);
109
+ const recipient = sibling.freshAddress;
110
+ return {
111
+ transaction: bridge.createTransaction(account),
112
+ updates: [
113
+ { recipient },
114
+ { useAllAmount: true },
115
+ Math.random() < 0.5
116
+ ? {
117
+ memo: "LedgerLiveBot",
118
+ }
119
+ : null,
120
+ ],
121
+ };
122
+ },
123
+ },
124
+ {
125
+ name: "delegate new validators",
126
+ maxRun: 1,
127
+ transaction: ({ account, bridge }) => {
128
+ invariant(
129
+ account.index % 2 > 0,
130
+ "only one out of 2 accounts is not going to delegate"
131
+ );
132
+ invariant(canDelegate(account), "can delegate");
133
+ const { cosmosResources } = account as CosmosAccount;
134
+ invariant(cosmosResources, "cosmos");
135
+ invariant(
136
+ (cosmosResources as CosmosResources).delegations.length < 3,
137
+ "already enough delegations"
138
+ );
139
+ const data = getCurrentOsmosisPreloadData();
140
+ const count = 1; // number of delegations to perform in a single tx
141
+ let remaining = getMaxDelegationAvailable(account, count)
142
+ .minus(minimalAmount.times(2))
143
+ .times(0.5 * Math.random());
144
+ invariant(remaining.gt(0), "not enough funds in account for delegate");
145
+ const all = data.validators.filter(
146
+ (v) =>
147
+ !(cosmosResources as CosmosResources).delegations.some(
148
+ // new delegations only
149
+ (d) => d.validatorAddress === v.validatorAddress
150
+ )
151
+ );
152
+ const validators = sampleSize(all, count)
153
+ .map((delegation) => {
154
+ // take a bit of remaining each time (less is preferred with the random() square)
155
+ const amount = remaining
156
+ .times(Math.random() * Math.random())
157
+ .integerValue();
158
+ remaining = remaining.minus(amount);
159
+ return {
160
+ address: delegation.validatorAddress,
161
+ amount,
162
+ };
163
+ })
164
+ .filter((v) => v.amount.gt(0));
165
+ invariant(validators.length > 0, "no possible delegation found");
166
+ return {
167
+ transaction: bridge.createTransaction(account),
168
+ updates: [
169
+ {
170
+ memo: "LedgerLiveBot",
171
+ mode: "delegate",
172
+ },
173
+ ...validators.map((_, i) => ({
174
+ validators: validators.slice(0, i + 1),
175
+ })),
176
+ ],
177
+ };
178
+ },
179
+ test: ({ account, transaction }) => {
180
+ const { cosmosResources } = account as CosmosAccount;
181
+ invariant(cosmosResources, "cosmos");
182
+ transaction.validators.forEach((v) => {
183
+ const d = (cosmosResources as CosmosResources).delegations.find(
184
+ (d) => d.validatorAddress === v.address
185
+ );
186
+ invariant(d, "delegated %s must be found in account", v.address);
187
+ expect({
188
+ address: v.address,
189
+ amount: approximateValue(v.amount),
190
+ }).toMatchObject({
191
+ address: (d as CosmosDelegation).validatorAddress,
192
+ amount: approximateValue((d as CosmosDelegation).amount),
193
+ });
194
+ });
195
+ },
196
+ },
197
+ {
198
+ name: "undelegate",
199
+ maxRun: 3,
200
+ transaction: ({ account, bridge }) => {
201
+ invariant(canUndelegate(account as CosmosAccount), "can undelegate");
202
+ const { cosmosResources } = account as CosmosAccount;
203
+ invariant(cosmosResources, "cosmos");
204
+ invariant(
205
+ (cosmosResources as CosmosResources).delegations.length > 0,
206
+ "already enough delegations"
207
+ );
208
+ const undelegateCandidate = sample(
209
+ (cosmosResources as CosmosResources).delegations.filter(
210
+ (d) =>
211
+ !(cosmosResources as CosmosResources).redelegations.some(
212
+ (r) =>
213
+ r.validatorSrcAddress === d.validatorAddress ||
214
+ r.validatorDstAddress === d.validatorAddress
215
+ ) &&
216
+ !(cosmosResources as CosmosResources).unbondings.some(
217
+ (r) => r.validatorAddress === d.validatorAddress
218
+ )
219
+ )
220
+ );
221
+ invariant(undelegateCandidate, "already pending");
222
+
223
+ const amount = (undelegateCandidate as CosmosDelegation).amount // most of the time, undelegate all
224
+ .times(Math.random() > 0.3 ? 1 : Math.random())
225
+ .integerValue();
226
+ invariant(amount.gt(0), "random amount to be positive");
227
+
228
+ return {
229
+ transaction: bridge.createTransaction(account),
230
+ updates: [
231
+ {
232
+ mode: "undelegate",
233
+ memo: "LedgerLiveBot",
234
+ },
235
+ {
236
+ validators: [
237
+ {
238
+ address: (undelegateCandidate as CosmosDelegation)
239
+ .validatorAddress,
240
+ amount,
241
+ },
242
+ ],
243
+ },
244
+ ],
245
+ };
246
+ },
247
+ test: ({ account, transaction }) => {
248
+ const { cosmosResources } = account as CosmosAccount;
249
+ invariant(cosmosResources, "cosmos");
250
+ transaction.validators.forEach((v) => {
251
+ const d = (cosmosResources as CosmosResources).unbondings.find(
252
+ (d) => d.validatorAddress === v.address
253
+ );
254
+ invariant(d, "undelegated %s must be found in account", v.address);
255
+ expect({
256
+ address: v.address,
257
+ amount: approximateValue(v.amount),
258
+ }).toMatchObject({
259
+ address: (d as CosmosUnbonding).validatorAddress,
260
+ amount: approximateValue((d as CosmosUnbonding).amount),
261
+ });
262
+ });
263
+ },
264
+ },
265
+ {
266
+ name: "redelegate",
267
+ maxRun: 1,
268
+ transaction: ({ account, bridge }) => {
269
+ const { cosmosResources } = account as CosmosAccount;
270
+ invariant(cosmosResources, "cosmos");
271
+ const sourceDelegation = sample(
272
+ (cosmosResources as CosmosResources).delegations.filter((d) =>
273
+ canRedelegate(account as CosmosAccount, d)
274
+ )
275
+ );
276
+ invariant(sourceDelegation, "none can redelegate");
277
+ const delegation = sample(
278
+ (cosmosResources as CosmosResources).delegations.filter(
279
+ (d) =>
280
+ d.validatorAddress !==
281
+ (sourceDelegation as CosmosDelegation).validatorAddress
282
+ )
283
+ );
284
+ const amount = (sourceDelegation as CosmosDelegation).amount
285
+ .times(
286
+ // most of the time redelegate all
287
+ Math.random() > 0.3 ? 1 : Math.random()
288
+ )
289
+ .integerValue();
290
+ invariant(amount.gt(0), "random amount to be positive");
291
+ return {
292
+ transaction: bridge.createTransaction(account),
293
+ updates: [
294
+ {
295
+ mode: "redelegate",
296
+ memo: "LedgerLiveBot",
297
+ sourceValidator: (sourceDelegation as CosmosDelegation)
298
+ .validatorAddress,
299
+ validators: [
300
+ {
301
+ address: (delegation as CosmosDelegation).validatorAddress,
302
+ amount,
303
+ },
304
+ ],
305
+ },
306
+ ],
307
+ };
308
+ },
309
+ test: ({ account, transaction }) => {
310
+ const { cosmosResources } = account as CosmosAccount;
311
+ invariant(cosmosResources, "cosmos");
312
+ transaction.validators.forEach((v) => {
313
+ // we possibly are moving from one existing delegation to another existing.
314
+ // in that case it's not a redelegation, it effects immediately
315
+ const existing = (
316
+ cosmosResources as CosmosResources
317
+ ).delegations.find((d) => d.validatorAddress === v.address);
318
+ if (!existing) {
319
+ // in other case, we will find it in a redelegation
320
+ const d = (cosmosResources as CosmosResources).redelegations
321
+ .slice(0) // recent first
322
+ .sort(
323
+ // FIXME: valueOf for date arithmetic operations in typescript
324
+ (a, b) =>
325
+ b.completionDate.valueOf() - a.completionDate.valueOf()
326
+ ) // find the related redelegation
327
+ .find(
328
+ (d) =>
329
+ d.validatorDstAddress === v.address &&
330
+ d.validatorSrcAddress === transaction.sourceValidator
331
+ );
332
+ invariant(d, "redelegated %s must be found in account", v.address);
333
+ expect({
334
+ address: v.address,
335
+ amount: approximateValue(v.amount),
336
+ }).toMatchObject({
337
+ address: (d as CosmosRedelegation).validatorDstAddress,
338
+ amount: approximateValue((d as CosmosRedelegation).amount),
339
+ });
340
+ }
341
+ });
342
+ },
343
+ },
344
+ {
345
+ name: "claim rewards",
346
+ maxRun: 1,
347
+ transaction: ({ account, bridge }) => {
348
+ const { cosmosResources } = account as CosmosAccount;
349
+ invariant(cosmosResources, "cosmos");
350
+ const delegation = sample(
351
+ (cosmosResources as CosmosResources).delegations.filter((d) =>
352
+ d.pendingRewards.gt(1000)
353
+ )
354
+ ) as CosmosDelegation;
355
+
356
+ invariant(delegation, "no delegation to claim");
357
+ return {
358
+ transaction: bridge.createTransaction(account),
359
+ updates: [
360
+ {
361
+ mode: "claimReward",
362
+ memo: "LedgerLiveBot",
363
+ validators: [
364
+ {
365
+ address: delegation.validatorAddress,
366
+ amount: delegation.pendingRewards,
367
+ },
368
+ ],
369
+ },
370
+ ],
371
+ };
372
+ },
373
+ test: ({ account, transaction }) => {
374
+ const { cosmosResources } = account as CosmosAccount;
375
+ invariant(cosmosResources, "cosmos");
376
+ transaction.validators.forEach((v) => {
377
+ const d = (cosmosResources as CosmosResources).delegations.find(
378
+ (d) => d.validatorAddress === v.address
379
+ );
380
+ invariant(d, "delegation %s must be found in account", v.address);
381
+ invariant(
382
+ !canClaimRewards(account as CosmosAccount, d as CosmosDelegation),
383
+ "reward no longer be claimable"
384
+ );
385
+ });
386
+ },
387
+ },
388
+ ],
389
+ };
390
+
391
+ export default {
392
+ osmosis,
393
+ };
@@ -0,0 +1,94 @@
1
+ import type { DeviceAction } from "../../bot/types";
2
+ import { deviceActionFlow } from "../../bot/specs";
3
+ import type { Transaction } from "./types";
4
+ const typeWording = {
5
+ send: "Send",
6
+ delegate: "Delegate",
7
+ redelegate: "Redelegate",
8
+ undelegate: "Undelegate",
9
+ claimReward: "Withdraw Reward",
10
+ claimRewardCompound: "(not tested)",
11
+ };
12
+ const acceptTransaction: DeviceAction<Transaction, any> = deviceActionFlow({
13
+ steps: [
14
+ {
15
+ title: "Sequence",
16
+ button: "Rr",
17
+ },
18
+ {
19
+ title: "Chain ID",
20
+ button: "Rr",
21
+ },
22
+ {
23
+ title: "Account",
24
+ button: "Rr",
25
+ },
26
+ {
27
+ title: "Type",
28
+ button: "Rr",
29
+ expectedValue: ({ transaction }) => typeWording[transaction.mode],
30
+ },
31
+ {
32
+ title: "Validator Source",
33
+ button: "Rr",
34
+ expectedValue: ({ transaction }) => transaction.sourceValidator || "",
35
+ },
36
+ {
37
+ title: "Validator Dest",
38
+ button: "Rr",
39
+ expectedValue: ({ transaction }) => transaction.validators[0].address,
40
+ },
41
+ {
42
+ title: "Validator",
43
+ button: "Rr",
44
+ expectedValue: ({ transaction }, acc) =>
45
+ transaction.validators[
46
+ acc.filter((a) => a.title === "Validator").length
47
+ ].address,
48
+ },
49
+ {
50
+ title: "Memo",
51
+ button: "Rr",
52
+ expectedValue: ({ transaction }) => transaction.memo || "",
53
+ },
54
+ {
55
+ title: "Fee",
56
+ button: "Rr",
57
+ },
58
+ {
59
+ title: "Gas",
60
+ button: "Rr",
61
+ expectedValue: ({ transaction }) => transaction.gas?.toString() || "",
62
+ },
63
+ {
64
+ title: "Amount",
65
+ button: "Rr",
66
+ },
67
+ {
68
+ title: "From",
69
+ button: "Rr",
70
+ expectedValue: ({ account }) => account.freshAddress,
71
+ },
72
+ {
73
+ title: "To",
74
+ button: "Rr",
75
+ expectedValue: ({ transaction }) => transaction.recipient,
76
+ },
77
+ {
78
+ title: "Delegator",
79
+ button: "Rr",
80
+ expectedValue: ({ account }) => account.freshAddress,
81
+ },
82
+ {
83
+ title: "APPROVE",
84
+ button: "LRlr",
85
+ final: true,
86
+ },
87
+ {
88
+ title: "REJECT",
89
+ },
90
+ ],
91
+ });
92
+ export default {
93
+ acceptTransaction,
94
+ };
@@ -0,0 +1,20 @@
1
+ import {
2
+ formatTransaction,
3
+ fromTransactionRaw,
4
+ toTransactionRaw,
5
+ } from "../cosmos/transaction";
6
+
7
+ import {
8
+ formatTransactionStatusCommon as formatTransactionStatus,
9
+ fromTransactionStatusRawCommon as fromTransactionStatusRaw,
10
+ toTransactionStatusRawCommon as toTransactionStatusRaw,
11
+ } from "../../transaction/common";
12
+
13
+ export default {
14
+ formatTransaction,
15
+ fromTransactionRaw,
16
+ toTransactionRaw,
17
+ fromTransactionStatusRaw,
18
+ toTransactionStatusRaw,
19
+ formatTransactionStatus,
20
+ };
@@ -0,0 +1,48 @@
1
+ import type { BigNumber } from "bignumber.js";
2
+ import {
3
+ TransactionStatusCommon,
4
+ TransactionStatusCommonRaw,
5
+ } from "@ledgerhq/types-live";
6
+ import {
7
+ CosmosLikeTransaction,
8
+ CosmosLikeTransactionRaw,
9
+ } from "../cosmos/types";
10
+ import { CosmosDelegationInfo, CosmosDelegationInfoRaw } from "../cosmos/types";
11
+
12
+ export type Transaction = CosmosLikeTransaction & {
13
+ family: "osmosis";
14
+ mode: string;
15
+ fees: BigNumber | null;
16
+ gas: BigNumber | null | undefined;
17
+ memo: string | null | undefined;
18
+ validators: CosmosDelegationInfo[];
19
+ sourceValidator: string | null | undefined;
20
+ };
21
+
22
+ export type TransactionRaw = CosmosLikeTransactionRaw & {
23
+ family: "osmosis";
24
+ mode: string;
25
+ fees: string | null;
26
+ gas: string | null | undefined;
27
+ memo: string | null | undefined;
28
+ validators: CosmosDelegationInfoRaw[];
29
+ sourceValidator: string | null | undefined;
30
+ };
31
+
32
+ export type TransactionStatus = TransactionStatusCommon;
33
+
34
+ export type TransactionStatusRaw = TransactionStatusCommonRaw;
35
+
36
+ export type OsmosisRewardsState = {
37
+ targetBondedRatio: number;
38
+ communityPoolCommission: number;
39
+ assumedTimePerBlock: number;
40
+ inflationRateChange: number;
41
+ inflationMaxRate: number;
42
+ inflationMinRate: number;
43
+ actualBondedRatio: number;
44
+ averageTimePerBlock: number;
45
+ totalSupply: number;
46
+ averageDailyFees: number;
47
+ currentValueInflation: number;
48
+ };
@@ -0,0 +1,31 @@
1
+ import { decode } from "bech32";
2
+
3
+ // Address validation freely inspired from
4
+ // https://github.com/terra-money/terra.js/blob/9e5f553de3ff3e975eaaf91b1f06e45658b1a5e0/src/core/bech32.ts
5
+ function checkPrefixAndLength(
6
+ prefix: string,
7
+ data: string,
8
+ length: number
9
+ ): boolean {
10
+ try {
11
+ const vals = decode(data);
12
+ return vals.prefix === prefix && data.length == length;
13
+ } catch (e) {
14
+ return false;
15
+ }
16
+ }
17
+
18
+ /**
19
+ * Checks if a string is a valid Osmosis account address.
20
+ *
21
+ * @param addr string to check
22
+ */
23
+ export function isValidAddress(currencyPrefix: string, addr: string): boolean {
24
+ return checkPrefixAndLength(currencyPrefix, addr, 43);
25
+ }
26
+
27
+ // export const FIGMENT_OSMOSIS_VALIDATOR_ADDRESS =
28
+ // "osmovaloper1hjct6q7npsspsg3dgvzk3sdf89spmlpf6t4agt";
29
+
30
+ export const LEDGER_OSMOSIS_VALIDATOR_ADDRESS =
31
+ "osmovaloper17cp6fxccqxrpj4zc00w2c7u6y0umc2jajsyc5t";
@@ -0,0 +1,79 @@
1
+ import { getCryptoCurrencyById } from "../../currencies";
2
+ import { CosmosValidatorsManager } from "../cosmos/CosmosValidatorsManager";
3
+ import { nodeEndpoint } from "./api/sdk";
4
+ import { osmosisAPI } from "./api/sdk";
5
+ import {
6
+ OsmosisDistributionParams,
7
+ OsmosisPool,
8
+ OsmosisTotalSupply,
9
+ } from "./OsmosisSupplyTypes";
10
+ import { OsmosisRewardsState } from "./types";
11
+
12
+ const osmosisCryptoCurrency = getCryptoCurrencyById("osmo");
13
+
14
+ // TODO Refactor this to be a class so that we don't have to query the API multiple times
15
+ const getRewardsState = async (): Promise<OsmosisRewardsState> => {
16
+ const distributionParams = await _getDistributionParams();
17
+ const supply = await _getTotalSupply();
18
+ const totalSupply = parseUOsmoStrAsOsmoNumber(supply.amount);
19
+ const pool = await _getPool();
20
+
21
+ const actualBondedRatio =
22
+ parseUOsmoStrAsOsmoNumber(pool.bonded_tokens) / totalSupply;
23
+ const communityPoolCommission = parseFloat(distributionParams.community_tax);
24
+
25
+ // Hardcoded mock values
26
+ const targetBondedRatio = 0.1;
27
+ const assumedTimePerBlock = 7;
28
+ const inflationRateChange = 0.01;
29
+ const inflationMaxRate = 0.01;
30
+ const inflationMinRate = 0.01;
31
+ const averageTimePerBlock = 7;
32
+ const averageDailyFees = 0;
33
+ const currentValueInflation = 0.01;
34
+
35
+ return {
36
+ targetBondedRatio,
37
+ communityPoolCommission,
38
+ assumedTimePerBlock,
39
+ inflationRateChange,
40
+ inflationMaxRate,
41
+ inflationMinRate,
42
+ actualBondedRatio,
43
+ averageTimePerBlock,
44
+ totalSupply,
45
+ averageDailyFees,
46
+ currentValueInflation,
47
+ };
48
+ };
49
+
50
+ const _getTotalSupply = async (): Promise<OsmosisTotalSupply> => {
51
+ const denom = osmosisCryptoCurrency.units[1].code;
52
+ const totalSupply = await osmosisAPI.queryTotalSupply(denom);
53
+ return totalSupply;
54
+ };
55
+
56
+ const _getPool = async (): Promise<OsmosisPool> => {
57
+ const pool = await osmosisAPI.queryPool();
58
+ return pool;
59
+ };
60
+
61
+ const _getDistributionParams = async (): Promise<OsmosisDistributionParams> => {
62
+ const distributionParams = await osmosisAPI.queryDistributionParams();
63
+ return distributionParams;
64
+ };
65
+
66
+ const parseUOsmoStrAsOsmoNumber = (uosmos: string) => {
67
+ return parseFloat(uosmos) / 1000000.0;
68
+ };
69
+
70
+ const osmosisValidatorsManager = new CosmosValidatorsManager(
71
+ osmosisCryptoCurrency,
72
+ {
73
+ endPoint: nodeEndpoint,
74
+ namespace: "osmosis",
75
+ rewardsState: async () => getRewardsState(),
76
+ }
77
+ );
78
+
79
+ export default osmosisValidatorsManager;
@@ -14,6 +14,9 @@ export const defaultFeatures: DefaultFeatures = {
14
14
  debug: false,
15
15
  },
16
16
  },
17
+ currencyOsmosis: {
18
+ enabled: false,
19
+ },
17
20
  ratings: {
18
21
  enabled: false,
19
22
  params: {
@@ -10,6 +10,8 @@ import elrond from "../families/elrond/account";
10
10
 
11
11
  import filecoin from "../families/filecoin/account";
12
12
 
13
+ import osmosis from "../families/osmosis/account";
14
+
13
15
  import polkadot from "../families/polkadot/account";
14
16
 
15
17
 
@@ -20,5 +22,6 @@ export default {
20
22
  crypto_org,
21
23
  elrond,
22
24
  filecoin,
25
+ osmosis,
23
26
  polkadot,
24
27
  };