@ritbit/v4-client-js 2.4.0 → 2.4.2

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 (296) hide show
  1. package/build/cjs/src/clients/composite-client.js +10 -9
  2. package/build/cjs/tsconfig.cjs.tsbuildinfo +1 -1
  3. package/build/esm/src/clients/composite-client.d.ts +3 -3
  4. package/build/esm/src/clients/composite-client.d.ts.map +1 -1
  5. package/build/esm/src/clients/composite-client.js +10 -9
  6. package/build/esm/tsconfig.esm.tsbuildinfo +1 -1
  7. package/package.json +11 -3
  8. package/.env +0 -1
  9. package/.eslintignore +0 -2
  10. package/.eslintrc.js +0 -15
  11. package/.gitleaks.toml +0 -24
  12. package/.gitleaksignore +0 -1
  13. package/.nvmrc +0 -1
  14. package/.prettierignore +0 -3
  15. package/.prettierrc.json +0 -6
  16. package/.releaserc +0 -10
  17. package/.vscode/launch.json +0 -11
  18. package/__native__/__ios__/v4-native-client.js +0 -251395
  19. package/__native__/__ios__/v4-native-client.js.map +0 -1
  20. package/__tests__/clients/composite-client.test.ts +0 -140
  21. package/__tests__/helpers/baseClients.ts +0 -23
  22. package/__tests__/helpers/constants.ts +0 -131
  23. package/__tests__/lib/helpers.test.ts +0 -55
  24. package/__tests__/lib/util.test.ts +0 -77
  25. package/__tests__/lib/validation.test.ts +0 -289
  26. package/__tests__/modules/client/AccountEndpoints.test.ts +0 -236
  27. package/__tests__/modules/client/FaucetEndpoint.test.ts +0 -14
  28. package/__tests__/modules/client/MarketsEndpoints.test.ts +0 -84
  29. package/__tests__/modules/client/Transfers.test.ts +0 -44
  30. package/__tests__/modules/client/UtilityEndpoints.test.ts +0 -29
  31. package/__tests__/modules/client/ValidatorGetEndpoints.test.ts +0 -50
  32. package/__tests__/modules/client/ValidatorPostEndpoints.test.ts +0 -52
  33. package/__tests__/modules/client/constants.ts +0 -5
  34. package/__tests__/modules/onboarding.test.ts +0 -66
  35. package/build/cjs/__tests__/clients/composite-client.test.js +0 -130
  36. package/build/cjs/__tests__/helpers/baseClients.js +0 -29
  37. package/build/cjs/__tests__/helpers/constants.js +0 -110
  38. package/build/cjs/__tests__/lib/helpers.test.js +0 -46
  39. package/build/cjs/__tests__/lib/util.test.js +0 -67
  40. package/build/cjs/__tests__/lib/validation.test.js +0 -254
  41. package/build/cjs/__tests__/modules/client/AccountEndpoints.test.js +0 -171
  42. package/build/cjs/__tests__/modules/client/FaucetEndpoint.test.js +0 -15
  43. package/build/cjs/__tests__/modules/client/MarketsEndpoints.test.js +0 -69
  44. package/build/cjs/__tests__/modules/client/Transfers.test.js +0 -44
  45. package/build/cjs/__tests__/modules/client/UtilityEndpoints.test.js +0 -28
  46. package/build/cjs/__tests__/modules/client/ValidatorGetEndpoints.test.js +0 -46
  47. package/build/cjs/__tests__/modules/client/ValidatorPostEndpoints.test.js +0 -53
  48. package/build/cjs/__tests__/modules/client/constants.js +0 -7
  49. package/build/cjs/__tests__/modules/onboarding.test.js +0 -50
  50. package/build/cjs/examples/account_endpoints.js +0 -129
  51. package/build/cjs/examples/batch_cancel_orders_example.js +0 -93
  52. package/build/cjs/examples/composite_example.js +0 -50
  53. package/build/cjs/examples/constants.js +0 -35
  54. package/build/cjs/examples/faucet_endpoint.js +0 -23
  55. package/build/cjs/examples/gov_add_new_market.js +0 -77
  56. package/build/cjs/examples/human_readable_orders.json +0 -86
  57. package/build/cjs/examples/human_readable_short_term_orders.json +0 -42
  58. package/build/cjs/examples/json-encoding.js +0 -32
  59. package/build/cjs/examples/long_term_order_cancel_example.js +0 -63
  60. package/build/cjs/examples/markets_endpoints.js +0 -134
  61. package/build/cjs/examples/native_examples.js +0 -112
  62. package/build/cjs/examples/noble_example.js +0 -88
  63. package/build/cjs/examples/optimal_node.js +0 -70
  64. package/build/cjs/examples/permissioned_keys_example.js +0 -104
  65. package/build/cjs/examples/raw_orders.json +0 -130
  66. package/build/cjs/examples/short_term_order_cancel_example.js +0 -54
  67. package/build/cjs/examples/short_term_order_composite_example.js +0 -68
  68. package/build/cjs/examples/test.js +0 -50
  69. package/build/cjs/examples/transfer_example_deposit.js +0 -29
  70. package/build/cjs/examples/transfer_example_send.js +0 -42
  71. package/build/cjs/examples/transfer_example_subaccount_transfer.js +0 -29
  72. package/build/cjs/examples/transfer_example_withdraw.js +0 -30
  73. package/build/cjs/examples/transfer_example_withdraw_other.js +0 -42
  74. package/build/cjs/examples/utility_endpoints.js +0 -42
  75. package/build/cjs/examples/validator_get_example.js +0 -158
  76. package/build/cjs/examples/validator_post_example.js +0 -76
  77. package/build/cjs/examples/wallet_address.js +0 -22
  78. package/build/cjs/examples/websocket_example.js +0 -36
  79. package/build/cjs/examples/websocket_orderbook_example.js +0 -196
  80. package/build/esm/__tests__/clients/composite-client.test.d.ts +0 -2
  81. package/build/esm/__tests__/clients/composite-client.test.d.ts.map +0 -1
  82. package/build/esm/__tests__/clients/composite-client.test.js +0 -128
  83. package/build/esm/__tests__/helpers/baseClients.d.ts +0 -19
  84. package/build/esm/__tests__/helpers/baseClients.d.ts.map +0 -1
  85. package/build/esm/__tests__/helpers/baseClients.js +0 -22
  86. package/build/esm/__tests__/helpers/constants.d.ts +0 -19
  87. package/build/esm/__tests__/helpers/constants.d.ts.map +0 -1
  88. package/build/esm/__tests__/helpers/constants.js +0 -104
  89. package/build/esm/__tests__/lib/helpers.test.d.ts +0 -2
  90. package/build/esm/__tests__/lib/helpers.test.d.ts.map +0 -1
  91. package/build/esm/__tests__/lib/helpers.test.js +0 -41
  92. package/build/esm/__tests__/lib/util.test.d.ts +0 -2
  93. package/build/esm/__tests__/lib/util.test.d.ts.map +0 -1
  94. package/build/esm/__tests__/lib/util.test.js +0 -65
  95. package/build/esm/__tests__/lib/validation.test.d.ts +0 -2
  96. package/build/esm/__tests__/lib/validation.test.d.ts.map +0 -1
  97. package/build/esm/__tests__/lib/validation.test.js +0 -249
  98. package/build/esm/__tests__/modules/client/AccountEndpoints.test.d.ts +0 -2
  99. package/build/esm/__tests__/modules/client/AccountEndpoints.test.d.ts.map +0 -1
  100. package/build/esm/__tests__/modules/client/AccountEndpoints.test.js +0 -169
  101. package/build/esm/__tests__/modules/client/FaucetEndpoint.test.d.ts +0 -2
  102. package/build/esm/__tests__/modules/client/FaucetEndpoint.test.d.ts.map +0 -1
  103. package/build/esm/__tests__/modules/client/FaucetEndpoint.test.js +0 -13
  104. package/build/esm/__tests__/modules/client/MarketsEndpoints.test.d.ts +0 -2
  105. package/build/esm/__tests__/modules/client/MarketsEndpoints.test.d.ts.map +0 -1
  106. package/build/esm/__tests__/modules/client/MarketsEndpoints.test.js +0 -66
  107. package/build/esm/__tests__/modules/client/Transfers.test.d.ts +0 -2
  108. package/build/esm/__tests__/modules/client/Transfers.test.d.ts.map +0 -1
  109. package/build/esm/__tests__/modules/client/Transfers.test.js +0 -39
  110. package/build/esm/__tests__/modules/client/UtilityEndpoints.test.d.ts +0 -2
  111. package/build/esm/__tests__/modules/client/UtilityEndpoints.test.d.ts.map +0 -1
  112. package/build/esm/__tests__/modules/client/UtilityEndpoints.test.js +0 -26
  113. package/build/esm/__tests__/modules/client/ValidatorGetEndpoints.test.d.ts +0 -2
  114. package/build/esm/__tests__/modules/client/ValidatorGetEndpoints.test.d.ts.map +0 -1
  115. package/build/esm/__tests__/modules/client/ValidatorGetEndpoints.test.js +0 -44
  116. package/build/esm/__tests__/modules/client/ValidatorPostEndpoints.test.d.ts +0 -2
  117. package/build/esm/__tests__/modules/client/ValidatorPostEndpoints.test.d.ts.map +0 -1
  118. package/build/esm/__tests__/modules/client/ValidatorPostEndpoints.test.js +0 -48
  119. package/build/esm/__tests__/modules/client/constants.d.ts +0 -4
  120. package/build/esm/__tests__/modules/client/constants.d.ts.map +0 -1
  121. package/build/esm/__tests__/modules/client/constants.js +0 -4
  122. package/build/esm/__tests__/modules/onboarding.test.d.ts +0 -2
  123. package/build/esm/__tests__/modules/onboarding.test.d.ts.map +0 -1
  124. package/build/esm/__tests__/modules/onboarding.test.js +0 -48
  125. package/build/esm/examples/account_endpoints.d.ts +0 -5
  126. package/build/esm/examples/account_endpoints.d.ts.map +0 -1
  127. package/build/esm/examples/account_endpoints.js +0 -127
  128. package/build/esm/examples/batch_cancel_orders_example.d.ts +0 -2
  129. package/build/esm/examples/batch_cancel_orders_example.d.ts.map +0 -1
  130. package/build/esm/examples/batch_cancel_orders_example.js +0 -88
  131. package/build/esm/examples/composite_example.d.ts +0 -2
  132. package/build/esm/examples/composite_example.d.ts.map +0 -1
  133. package/build/esm/examples/composite_example.js +0 -45
  134. package/build/esm/examples/constants.d.ts +0 -13
  135. package/build/esm/examples/constants.d.ts.map +0 -1
  136. package/build/esm/examples/constants.js +0 -29
  137. package/build/esm/examples/faucet_endpoint.d.ts +0 -5
  138. package/build/esm/examples/faucet_endpoint.d.ts.map +0 -1
  139. package/build/esm/examples/faucet_endpoint.js +0 -21
  140. package/build/esm/examples/gov_add_new_market.d.ts +0 -2
  141. package/build/esm/examples/gov_add_new_market.d.ts.map +0 -1
  142. package/build/esm/examples/gov_add_new_market.js +0 -72
  143. package/build/esm/examples/human_readable_orders.json +0 -86
  144. package/build/esm/examples/human_readable_short_term_orders.json +0 -42
  145. package/build/esm/examples/json-encoding.d.ts +0 -2
  146. package/build/esm/examples/json-encoding.d.ts.map +0 -1
  147. package/build/esm/examples/json-encoding.js +0 -27
  148. package/build/esm/examples/long_term_order_cancel_example.d.ts +0 -2
  149. package/build/esm/examples/long_term_order_cancel_example.d.ts.map +0 -1
  150. package/build/esm/examples/long_term_order_cancel_example.js +0 -58
  151. package/build/esm/examples/markets_endpoints.d.ts +0 -5
  152. package/build/esm/examples/markets_endpoints.d.ts.map +0 -1
  153. package/build/esm/examples/markets_endpoints.js +0 -131
  154. package/build/esm/examples/native_examples.d.ts +0 -2
  155. package/build/esm/examples/native_examples.d.ts.map +0 -1
  156. package/build/esm/examples/native_examples.js +0 -110
  157. package/build/esm/examples/noble_example.d.ts +0 -2
  158. package/build/esm/examples/noble_example.d.ts.map +0 -1
  159. package/build/esm/examples/noble_example.js +0 -83
  160. package/build/esm/examples/optimal_node.d.ts +0 -2
  161. package/build/esm/examples/optimal_node.d.ts.map +0 -1
  162. package/build/esm/examples/optimal_node.js +0 -68
  163. package/build/esm/examples/permissioned_keys_example.d.ts +0 -2
  164. package/build/esm/examples/permissioned_keys_example.d.ts.map +0 -1
  165. package/build/esm/examples/permissioned_keys_example.js +0 -99
  166. package/build/esm/examples/raw_orders.json +0 -130
  167. package/build/esm/examples/short_term_order_cancel_example.d.ts +0 -2
  168. package/build/esm/examples/short_term_order_cancel_example.d.ts.map +0 -1
  169. package/build/esm/examples/short_term_order_cancel_example.js +0 -49
  170. package/build/esm/examples/short_term_order_composite_example.d.ts +0 -2
  171. package/build/esm/examples/short_term_order_composite_example.d.ts.map +0 -1
  172. package/build/esm/examples/short_term_order_composite_example.js +0 -63
  173. package/build/esm/examples/test.d.ts +0 -2
  174. package/build/esm/examples/test.d.ts.map +0 -1
  175. package/build/esm/examples/test.js +0 -45
  176. package/build/esm/examples/transfer_example_deposit.d.ts +0 -2
  177. package/build/esm/examples/transfer_example_deposit.d.ts.map +0 -1
  178. package/build/esm/examples/transfer_example_deposit.js +0 -24
  179. package/build/esm/examples/transfer_example_send.d.ts +0 -2
  180. package/build/esm/examples/transfer_example_send.d.ts.map +0 -1
  181. package/build/esm/examples/transfer_example_send.js +0 -37
  182. package/build/esm/examples/transfer_example_subaccount_transfer.d.ts +0 -2
  183. package/build/esm/examples/transfer_example_subaccount_transfer.d.ts.map +0 -1
  184. package/build/esm/examples/transfer_example_subaccount_transfer.js +0 -24
  185. package/build/esm/examples/transfer_example_withdraw.d.ts +0 -2
  186. package/build/esm/examples/transfer_example_withdraw.d.ts.map +0 -1
  187. package/build/esm/examples/transfer_example_withdraw.js +0 -25
  188. package/build/esm/examples/transfer_example_withdraw_other.d.ts +0 -2
  189. package/build/esm/examples/transfer_example_withdraw_other.d.ts.map +0 -1
  190. package/build/esm/examples/transfer_example_withdraw_other.js +0 -37
  191. package/build/esm/examples/utility_endpoints.d.ts +0 -5
  192. package/build/esm/examples/utility_endpoints.d.ts.map +0 -1
  193. package/build/esm/examples/utility_endpoints.js +0 -40
  194. package/build/esm/examples/validator_get_example.d.ts +0 -2
  195. package/build/esm/examples/validator_get_example.d.ts.map +0 -1
  196. package/build/esm/examples/validator_get_example.js +0 -156
  197. package/build/esm/examples/validator_post_example.d.ts +0 -2
  198. package/build/esm/examples/validator_post_example.d.ts.map +0 -1
  199. package/build/esm/examples/validator_post_example.js +0 -71
  200. package/build/esm/examples/wallet_address.d.ts +0 -2
  201. package/build/esm/examples/wallet_address.d.ts.map +0 -1
  202. package/build/esm/examples/wallet_address.js +0 -17
  203. package/build/esm/examples/websocket_example.d.ts +0 -2
  204. package/build/esm/examples/websocket_example.d.ts.map +0 -1
  205. package/build/esm/examples/websocket_example.js +0 -34
  206. package/build/esm/examples/websocket_orderbook_example.d.ts +0 -2
  207. package/build/esm/examples/websocket_orderbook_example.d.ts.map +0 -1
  208. package/build/esm/examples/websocket_orderbook_example.js +0 -194
  209. package/commitlint.config.js +0 -8
  210. package/examples/account_endpoints.ts +0 -129
  211. package/examples/batch_cancel_orders_example.ts +0 -130
  212. package/examples/composite_example.ts +0 -65
  213. package/examples/constants.ts +0 -42
  214. package/examples/faucet_endpoint.ts +0 -24
  215. package/examples/gov_add_new_market.json +0 -64
  216. package/examples/gov_add_new_market.ts +0 -95
  217. package/examples/human_readable_orders.json +0 -86
  218. package/examples/human_readable_short_term_orders.json +0 -42
  219. package/examples/json-encoding.ts +0 -33
  220. package/examples/long_term_order_cancel_example.ts +0 -87
  221. package/examples/markets_endpoints.ts +0 -134
  222. package/examples/native_examples.ts +0 -151
  223. package/examples/noble_example.ts +0 -107
  224. package/examples/optimal_node.ts +0 -70
  225. package/examples/permissioned_keys_example.ts +0 -162
  226. package/examples/raw_orders.json +0 -130
  227. package/examples/short_term_order_cancel_example.ts +0 -68
  228. package/examples/short_term_order_composite_example.ts +0 -80
  229. package/examples/test.ts +0 -65
  230. package/examples/transfer_example_deposit.ts +0 -28
  231. package/examples/transfer_example_send.ts +0 -60
  232. package/examples/transfer_example_subaccount_transfer.ts +0 -29
  233. package/examples/transfer_example_withdraw.ts +0 -31
  234. package/examples/transfer_example_withdraw_other.ts +0 -60
  235. package/examples/utility_endpoints.ts +0 -42
  236. package/examples/validator_get_example.ts +0 -160
  237. package/examples/validator_post_example.ts +0 -81
  238. package/examples/wallet_address.ts +0 -18
  239. package/examples/websocket_example.ts +0 -44
  240. package/examples/websocket_orderbook_example.ts +0 -239
  241. package/jest.config.js +0 -12
  242. package/jest.globalSetup.js +0 -5
  243. package/jest.setup.js +0 -1
  244. package/ritbit-v4-client-js-2.2.6.tgz +0 -0
  245. package/scripts/bump_version.sh +0 -16
  246. package/scripts/generate-cctp-protos.sh +0 -41
  247. package/scripts/mobile_build_pack.sh +0 -5
  248. package/scripts/publish-if-not-exists.sh +0 -21
  249. package/src/clients/composite-client.ts +0 -1469
  250. package/src/clients/constants.ts +0 -361
  251. package/src/clients/faucet-client.ts +0 -48
  252. package/src/clients/helpers/chain-helpers.ts +0 -231
  253. package/src/clients/helpers/request-helpers.ts +0 -71
  254. package/src/clients/indexer-client.ts +0 -61
  255. package/src/clients/lib/axios/axiosRequest.ts +0 -41
  256. package/src/clients/lib/axios/errors.ts +0 -41
  257. package/src/clients/lib/axios/index.ts +0 -7
  258. package/src/clients/lib/axios/types.ts +0 -6
  259. package/src/clients/lib/cctpProto.ts +0 -4197
  260. package/src/clients/lib/errors.ts +0 -63
  261. package/src/clients/lib/registry.ts +0 -93
  262. package/src/clients/modules/account.ts +0 -438
  263. package/src/clients/modules/composer.ts +0 -669
  264. package/src/clients/modules/get.ts +0 -791
  265. package/src/clients/modules/local-wallet.ts +0 -79
  266. package/src/clients/modules/markets.ts +0 -76
  267. package/src/clients/modules/post.ts +0 -1043
  268. package/src/clients/modules/proto-includes.ts +0 -34
  269. package/src/clients/modules/rest.ts +0 -40
  270. package/src/clients/modules/signer.ts +0 -139
  271. package/src/clients/modules/tendermintClient.ts +0 -168
  272. package/src/clients/modules/utility.ts +0 -47
  273. package/src/clients/modules/vault.ts +0 -23
  274. package/src/clients/native.ts +0 -1689
  275. package/src/clients/noble-client.ts +0 -108
  276. package/src/clients/socket-client.ts +0 -331
  277. package/src/clients/subaccount.ts +0 -57
  278. package/src/clients/types.ts +0 -191
  279. package/src/clients/validator-client.ts +0 -106
  280. package/src/index.ts +0 -19
  281. package/src/lib/constants.ts +0 -28
  282. package/src/lib/errors.ts +0 -38
  283. package/src/lib/helpers.ts +0 -99
  284. package/src/lib/onboarding.ts +0 -96
  285. package/src/lib/trading-key-utils.ts +0 -136
  286. package/src/lib/utils.ts +0 -84
  287. package/src/lib/validation.ts +0 -197
  288. package/src/network_optimizer.ts +0 -132
  289. package/src/types.ts +0 -44
  290. package/tasks.json +0 -16
  291. package/tsconfig.base.json +0 -21
  292. package/tsconfig.cjs.json +0 -10
  293. package/tsconfig.eslint.json +0 -14
  294. package/tsconfig.esm.json +0 -11
  295. package/tsconfig.json +0 -6
  296. package/webpack.config.js +0 -56
@@ -1,106 +0,0 @@
1
- import { QueryClient, TxExtension, setupTxExtension } from '@cosmjs/stargate';
2
- import { Tendermint37Client } from '@cosmjs/tendermint-rpc';
3
- import Long from 'long';
4
- import protobuf from 'protobufjs';
5
-
6
- import {
7
- ValidatorConfig,
8
- BROADCAST_POLL_INTERVAL_MS,
9
- BROADCAST_TIMEOUT_MS,
10
- SelectedGasDenom,
11
- } from './constants';
12
- import { Get } from './modules/get';
13
- import { Post } from './modules/post';
14
- import { TendermintClient } from './modules/tendermintClient';
15
-
16
- // Required for encoding and decoding queries that are of type Long.
17
- // Must be done once but since the individal modules should be usable
18
- // - must be set in each module that encounters encoding/decoding Longs.
19
- // Reference: https://github.com/protobufjs/protobuf.js/issues/921
20
- protobuf.util.Long = Long;
21
- protobuf.configure();
22
-
23
- export class ValidatorClient {
24
- public readonly config: ValidatorConfig;
25
- private _get?: Get;
26
- private _post?: Post;
27
-
28
- /**
29
- * @description Connect to a validator client
30
- *
31
- * @returns The validator client
32
- */
33
- static async connect(config: ValidatorConfig): Promise<ValidatorClient> {
34
- const client = new ValidatorClient(config);
35
- await client.initialize();
36
- return client;
37
- }
38
-
39
- private constructor(config: ValidatorConfig) {
40
- this.config = config;
41
- }
42
-
43
- /**
44
- * @description Get the query module, used for retrieving on-chain data.
45
- *
46
- * @returns The query module
47
- */
48
- get get(): Get {
49
- return this._get!;
50
- }
51
-
52
- /**
53
- * @description transaction module, used for sending transactions.
54
- *
55
- * @returns The transaction module
56
- */
57
- get post(): Post {
58
- return this._post!;
59
- }
60
-
61
- get selectedGasDenom(): SelectedGasDenom | undefined {
62
- if (!this._post) return undefined;
63
- return this._post.selectedGasDenom;
64
- }
65
-
66
- setSelectedGasDenom(gasDenom: SelectedGasDenom): void {
67
- if (!this._post) throw new Error('Post module not initialized');
68
-
69
- this._post.setSelectedGasDenom(gasDenom);
70
- }
71
-
72
- /**
73
- * @description populate account number cache in the Post module for performance.
74
- * @returns { typeUrl } при первом вызове; undefined при cache hit.
75
- */
76
- async populateAccountNumberCache(
77
- address: string
78
- ): Promise<{ typeUrl: string } | undefined> {
79
- if (!this._post) throw new Error('Post module not initialized');
80
- return this._post.populateAccountNumberCache(address);
81
- }
82
-
83
- private async initialize(): Promise<void> {
84
- const tendermint37Client: Tendermint37Client = await Tendermint37Client.connect(
85
- this.config.restEndpoint,
86
- );
87
-
88
- const tendermintClient = new TendermintClient(tendermint37Client, {
89
- broadcastPollIntervalMs: BROADCAST_POLL_INTERVAL_MS,
90
- broadcastTimeoutMs: BROADCAST_TIMEOUT_MS,
91
- });
92
- const queryClient: QueryClient & TxExtension = QueryClient.withExtensions(
93
- tendermint37Client,
94
- setupTxExtension,
95
- );
96
- this._get = new Get(tendermintClient, queryClient);
97
- this._post = new Post(
98
- this._get!,
99
- this.config.chainId,
100
- this.config.denoms,
101
- this.config.defaultClientMemo,
102
- this.config.useTimestampNonce,
103
- this.config.timestampNonceOffsetMs,
104
- );
105
- }
106
- }
package/src/index.ts DELETED
@@ -1,19 +0,0 @@
1
- // Types.
2
- export * from './types';
3
-
4
- // Utility functions.
5
- export * as helpers from './lib/helpers';
6
- export * as onboarding from './lib/onboarding';
7
- export * as tradingKeyUtils from './lib/trading-key-utils';
8
- export * as utils from './lib/utils';
9
- export * as validation from './lib/validation';
10
- export { CompositeClient } from './clients/composite-client';
11
- export { FaucetClient } from './clients/faucet-client';
12
- export { IndexerClient } from './clients/indexer-client';
13
- export { default as LocalWallet } from './clients/modules/local-wallet';
14
- export { NobleClient } from './clients/noble-client';
15
- export { SocketClient } from './clients/socket-client';
16
- export { SubaccountInfo as SubaccountClient, SubaccountInfo } from './clients/subaccount';
17
- export { ValidatorClient } from './clients/validator-client';
18
- export { encodeJson, ByteArrayEncoding } from './lib/helpers';
19
- export { NetworkOptimizer } from './network_optimizer';
@@ -1,28 +0,0 @@
1
- import { StdFee } from '@cosmjs/stargate';
2
-
3
- // Bech32 Prefix
4
- export const BECH32_PREFIX = 'rit';
5
- export const NOBLE_BECH32_PREFIX = 'noble';
6
-
7
- // Broadcast Defaults
8
- export const BROADCAST_POLL_INTERVAL_MS: number = 300;
9
- export const BROADCAST_TIMEOUT_MS: number = 8_000;
10
-
11
- // API Defaults
12
- export const API_TIMEOUT_DEFAULT_MS: number = 5_000;
13
-
14
- // Gas
15
- export const GAS_MULTIPLIER: number = 1.6;
16
-
17
- export const ZERO_FEE: StdFee = {
18
- amount: [],
19
- gas: '0',
20
- };
21
-
22
- // Validation
23
- export const MAX_UINT_32 = 4_294_967_295;
24
- export const MAX_SUBACCOUNT_NUMBER = 128_000;
25
-
26
- export const DEFAULT_SEQUENCE: number = 0;
27
-
28
- export const SERIALIZED_INT_ZERO: Uint8Array = Uint8Array.from([0x02]);
package/src/lib/errors.ts DELETED
@@ -1,38 +0,0 @@
1
- import { BroadcastTxSyncResponse } from '@cosmjs/tendermint-rpc';
2
-
3
- /**
4
- * An edge-case was hit in the client that should never have been reached.
5
- */
6
- export class UnexpectedClientError extends Error {
7
- constructor() {
8
- super('An unexpected error occurred on the client');
9
- this.name = 'UnexpectedClientError';
10
- }
11
- }
12
-
13
- /**
14
- * An error occurred during the broadcasting process.
15
- */
16
- export class BroadcastErrorObject extends Error {
17
- result: BroadcastTxSyncResponse;
18
- code: number;
19
- codespace?: string;
20
-
21
- constructor(message: string, result: BroadcastTxSyncResponse) {
22
- super(message);
23
- this.name = 'BroadcastError';
24
- this.result = result;
25
- this.code = result.code;
26
- this.codespace = result.codespace;
27
- }
28
- }
29
-
30
- /**
31
- * User error occurred during a client operation.
32
- */
33
- export class UserError extends Error {
34
- constructor(message: string) {
35
- super(message);
36
- this.name = 'UserError';
37
- }
38
- }
@@ -1,99 +0,0 @@
1
- import { toHex } from '@cosmjs/encoding';
2
- import BigNumber from 'bignumber.js';
3
- import Long from 'long';
4
-
5
- import { PartialTransactionOptions, TransactionOptions } from '../types';
6
- import { DEFAULT_SEQUENCE } from './constants';
7
-
8
- /**
9
- * @description Either return undefined or insert default sequence value into
10
- * `partialTransactionOptions` if it does not exist.
11
- *
12
- * @returns undefined or full TransactionOptions.
13
- */
14
- export function convertPartialTransactionOptionsToFull(
15
- partialTransactionOptions?: PartialTransactionOptions,
16
- ): TransactionOptions | undefined {
17
- if (partialTransactionOptions === undefined) {
18
- return undefined;
19
- }
20
-
21
- return {
22
- sequence: DEFAULT_SEQUENCE,
23
- ...partialTransactionOptions,
24
- };
25
- }
26
-
27
- /**
28
- * @description Strip '0x' prefix from input string. If there is no '0x' prefix, return the original
29
- * input.
30
- *
31
- * @returns input without '0x' prefix or original input if no prefix.
32
- */
33
- export function stripHexPrefix(input: string): string {
34
- if (input.indexOf('0x') === 0) {
35
- return input.slice(2);
36
- }
37
-
38
- return input;
39
- }
40
-
41
- function toBigInt(u: Uint8Array): BigInt {
42
- if (u.length <= 1) {
43
- return BigInt(0);
44
- }
45
- // eslint-disable-next-line no-bitwise
46
- const negated: boolean = (u[0] & 1) === 1;
47
- const hex: string = Buffer.from(u.slice(1)).toString('hex');
48
- const abs: bigint = BigInt(`0x${hex}`);
49
- return negated ? -abs : abs;
50
- }
51
-
52
- export function bigIntToBytes(value: bigint): Uint8Array {
53
- const absoluteValue = value < 0 ? value * BigInt(-1) : value;
54
- const nonPaddedHexValue = absoluteValue.toString(16);
55
- const paddedHexValue =
56
- nonPaddedHexValue.length % 2 === 0 ? nonPaddedHexValue : `0${nonPaddedHexValue}`;
57
- const numberBytes = Buffer.from(paddedHexValue, 'hex');
58
- const signedBytes = Uint8Array.of(value < 0 ? 3 : 2, ...numberBytes);
59
- return signedBytes;
60
- }
61
-
62
- export enum ByteArrayEncoding {
63
- HEX = 'hex',
64
- BIGINT = 'bigint',
65
- }
66
-
67
- export function encodeJson(
68
- object?: Object,
69
- byteArrayEncoding: ByteArrayEncoding = ByteArrayEncoding.HEX,
70
- ): string {
71
- // eslint-disable-next-line prefer-arrow-callback
72
- return JSON.stringify(object, function replacer(_key, value) {
73
- // Even though we set the an UInt8Array as the value,
74
- // it comes in here as an object with UInt8Array as the buffer property.
75
- if (value instanceof BigNumber) {
76
- return value.toString();
77
- }
78
- if (typeof value === 'bigint') {
79
- return value.toString();
80
- }
81
- if (value instanceof Long) {
82
- return value.toString();
83
- }
84
- if (value?.buffer instanceof Uint8Array) {
85
- if (byteArrayEncoding === ByteArrayEncoding.HEX) {
86
- return toHex(value.buffer);
87
- } else {
88
- return toBigInt(value.buffer).toString();
89
- }
90
- } else if (value instanceof Uint8Array) {
91
- if (byteArrayEncoding === ByteArrayEncoding.HEX) {
92
- return toHex(value);
93
- } else {
94
- return toBigInt(value).toString();
95
- }
96
- }
97
- return value;
98
- });
99
- }
@@ -1,96 +0,0 @@
1
- import { HDKey } from '@scure/bip32';
2
- import { entropyToMnemonic, mnemonicToSeedSync } from '@scure/bip39';
3
- import { wordlist } from '@scure/bip39/wordlists/english';
4
- import { keccak256 } from 'ethereum-cryptography/keccak';
5
-
6
- import { stripHexPrefix } from './helpers';
7
-
8
- /**
9
- * @description Get Mnemonic and priv/pub keys from privateKeyBytes and BIP44 HD path
10
- *
11
- * @url https://github.com/confio/cosmos-hd-key-derivation-spec#bip44
12
- *
13
- * @param entropy used to generate mnemonic
14
- *
15
- * @param path BIP44 HD Path. Default is The Cosmos Hub path
16
- *
17
- * @throws Error if the hdkey does not exist
18
- *
19
- * @returns Mnemonic and priv/pub keys
20
- */
21
- export const exportMnemonicAndPrivateKey = (
22
- entropy: Uint8Array,
23
- path: string = "m/44'/118'/0'/0/0",
24
- ): {
25
- mnemonic: string;
26
- privateKey: Uint8Array | null;
27
- publicKey: Uint8Array | null;
28
- } => {
29
- const mnemonic = entropyToMnemonic(entropy, wordlist);
30
- const { privateKey, publicKey } = deriveHDKeyFromMnemonic(mnemonic, path);
31
- return {
32
- mnemonic,
33
- privateKey,
34
- publicKey,
35
- };
36
- };
37
-
38
- /**
39
- * @description Get private information for onboarding using an Ethereum Signature.
40
- *
41
- * @returns Mnemonic and Public/Private HD keys
42
- */
43
- export const deriveHDKeyFromEthereumSignature = (
44
- signature: string,
45
- ): {
46
- mnemonic: string;
47
- privateKey: Uint8Array | null;
48
- publicKey: Uint8Array | null;
49
- } => {
50
- const buffer = Buffer.from(stripHexPrefix(signature), 'hex');
51
-
52
- if (buffer.length !== 65) {
53
- throw new Error('Signature must be 65 bytes');
54
- }
55
-
56
- // Remove the 'v' value by taking only the first 64 bytes of the signature
57
- const rsValues = buffer.subarray(0, 64);
58
- // Hash the 'r' and 's' values down to 32 bytes (256 bits) using Keccak-256
59
- const entropy = keccak256(rsValues);
60
- return exportMnemonicAndPrivateKey(entropy);
61
- };
62
-
63
- /**
64
- * @description Derive priv/pub keys from mnemonic and BIP44 HD path
65
- *
66
- * @url https://github.com/confio/cosmos-hd-key-derivation-spec#bip44
67
- *
68
- * @param mnemonic used to generate seed
69
- *
70
- * @param path BIP44 HD Path. Default is The Cosmos Hub path
71
- *
72
- * @throws Error if the hdkey does not exist
73
- *
74
- * @returns Priv/pub keys
75
- */
76
- export const deriveHDKeyFromMnemonic = (
77
- mnemonic: string,
78
- path: string = "m/44'/118'/0'/0/0",
79
- ): {
80
- privateKey: Uint8Array | null;
81
- publicKey: Uint8Array | null;
82
- } => {
83
- const seed = mnemonicToSeedSync(mnemonic);
84
-
85
- const hdkey = HDKey.fromMasterSeed(seed);
86
- const derivedHdkey = hdkey.derive(path);
87
-
88
- if (!hdkey.privateKey) {
89
- throw new Error('null hd key');
90
- }
91
-
92
- return {
93
- privateKey: derivedHdkey.privateKey,
94
- publicKey: derivedHdkey.publicKey,
95
- };
96
- };
@@ -1,136 +0,0 @@
1
- import { fromBase64, toBase64, toBech32, toHex } from '@cosmjs/encoding';
2
- import { rawSecp256k1PubkeyToRawAddress } from '@cosmjs/tendermint-rpc';
3
- import { generateMnemonic } from '@scure/bip39';
4
- import { wordlist } from '@scure/bip39/wordlists/english';
5
-
6
- import {
7
- Authenticator,
8
- AuthenticatorType,
9
- TYPE_URL_BATCH_CANCEL,
10
- TYPE_URL_MSG_CANCEL_ORDER,
11
- TYPE_URL_MSG_PLACE_ORDER,
12
- } from '../clients/constants';
13
- import { type Get } from '../clients/modules/get';
14
- import LocalWallet from '../clients/modules/local-wallet';
15
- import { BECH32_PREFIX } from './constants';
16
- import { deriveHDKeyFromMnemonic } from './onboarding';
17
-
18
- export const createNewRandomChainWallet = async (): Promise<
19
- { privateKeyHex: string; mnemonic: string; publicKey: string; address: string } | undefined
20
- > => {
21
- const mnemonic = generateMnemonic(wordlist, 128);
22
- const { privateKey: privateKeyRaw } = deriveHDKeyFromMnemonic(mnemonic);
23
- const wallet = await LocalWallet.fromMnemonic(mnemonic, BECH32_PREFIX);
24
-
25
- const privateKeyHex = privateKeyRaw != null ? `0x${toHex(privateKeyRaw)}` : undefined;
26
- const publicKey = wallet.pubKey;
27
- const address = wallet.address;
28
-
29
- if (privateKeyHex == null || publicKey == null || address == null) {
30
- return undefined;
31
- }
32
-
33
- return {
34
- // 12 english words
35
- mnemonic,
36
- // toHex of the raw private key bits
37
- privateKeyHex,
38
- // base64, not hex
39
- publicKey: publicKey.value,
40
- // valid chain address corresponding to the key pair
41
- address,
42
- };
43
- };
44
-
45
- // arguments to authorize a given wallet public key to trade on behalf of the user.
46
- // allows place order, cancel order, batch cancel on subaccount 0 only.
47
- export const getAuthorizeNewTradingKeyArguments = ({
48
- generatedWalletPubKey,
49
- }: {
50
- generatedWalletPubKey: string;
51
- }): { type: AuthenticatorType; data: Uint8Array } => {
52
- const wrapAndEncode64 = (s: string): string => toBase64(new TextEncoder().encode(s));
53
-
54
- const messageFilterSubAuth = [
55
- {
56
- type: AuthenticatorType.MESSAGE_FILTER,
57
- config: wrapAndEncode64(TYPE_URL_MSG_PLACE_ORDER),
58
- },
59
- {
60
- type: AuthenticatorType.MESSAGE_FILTER,
61
- config: wrapAndEncode64(TYPE_URL_MSG_CANCEL_ORDER),
62
- },
63
- {
64
- type: AuthenticatorType.MESSAGE_FILTER,
65
- config: wrapAndEncode64(TYPE_URL_BATCH_CANCEL),
66
- },
67
- ];
68
-
69
- const anyOfMessageFilterConfigB64 = wrapAndEncode64(JSON.stringify(messageFilterSubAuth));
70
-
71
- const subAuth = [
72
- {
73
- type: AuthenticatorType.SIGNATURE_VERIFICATION,
74
- config: generatedWalletPubKey,
75
- },
76
- {
77
- type: AuthenticatorType.ANY_OF,
78
- config: anyOfMessageFilterConfigB64,
79
- },
80
- // we limit to cross markets to make it slightly harder to drain user funds on low liquidity markets with trading keys
81
- // could undo this in the future if people are angry about it
82
- {
83
- type: AuthenticatorType.SUBACCOUNT_FILTER,
84
- config: wrapAndEncode64('0'),
85
- },
86
- ];
87
-
88
- const jsonString = JSON.stringify(subAuth);
89
- const encodedData = new TextEncoder().encode(jsonString);
90
- const topLevelType = AuthenticatorType.ALL_OF;
91
-
92
- return {
93
- type: topLevelType,
94
- data: encodedData,
95
- };
96
- };
97
-
98
- // redeclared to keep sub bundle size small
99
- type Awaited<T> = T extends Promise<infer U> ? U : T;
100
- const isTruthy = <T>(n?: T | false | null | undefined | 0): n is T => Boolean(n);
101
-
102
- // just parses out keys that match the format created in getAuthorizeNewTradingKeyArguments
103
- export const getAuthorizedTradingKeysMetadata = (
104
- authorizedKeys: Awaited<ReturnType<Get['getAuthenticators']>>['accountAuthenticators'],
105
- ): Array<{ id: string; publicKey: string; address: string }> => {
106
- return authorizedKeys
107
- .map(({ config, id, type }) => {
108
- if (type !== AuthenticatorType.ALL_OF) {
109
- return null;
110
- }
111
- const parsedConfig = JSON.parse(new TextDecoder().decode(config)) as
112
- | Authenticator[]
113
- | undefined;
114
- if (parsedConfig == null) {
115
- return null;
116
- }
117
-
118
- const publicKey = parsedConfig.find(
119
- (t) => t.type === AuthenticatorType.SIGNATURE_VERIFICATION,
120
- )?.config;
121
- if (publicKey == null || typeof publicKey !== 'string') {
122
- return null;
123
- }
124
-
125
- const address = toBech32(
126
- BECH32_PREFIX,
127
- rawSecp256k1PubkeyToRawAddress(fromBase64(publicKey)),
128
- );
129
- return {
130
- id: id.toString(),
131
- publicKey,
132
- address,
133
- };
134
- })
135
- .filter(isTruthy);
136
- };
package/src/lib/utils.ts DELETED
@@ -1,84 +0,0 @@
1
- import { AxiosProxyConfig } from 'axios';
2
- import { HttpsProxyAgent } from 'https-proxy-agent';
3
-
4
- import { MAX_UINT_32 } from '../clients/constants';
5
-
6
- /**
7
- * Returns a random integer value between 0 and (n-1).
8
- */
9
- export function randomInt(n: number): number {
10
- return Math.floor(Math.random() * n);
11
- }
12
-
13
- /**
14
- * Generate a random clientId.
15
- */
16
- export function generateRandomClientId(): number {
17
- return randomInt(MAX_UINT_32 + 1);
18
- }
19
-
20
- /**
21
- * Deterministically generate a valid clientId from an arbitrary string by performing a
22
- * quick hashing function on the string.
23
- */
24
- export function clientIdFromString(input: string): number {
25
- let hash: number = 0;
26
- if (input.length === 0) return hash;
27
- for (let i = 0; i < input.length; i++) {
28
- hash = (hash << 5) - hash + input.charCodeAt(i); // eslint-disable-line no-bitwise
29
- hash |= 0; // eslint-disable-line no-bitwise
30
- }
31
-
32
- // Bitwise operators covert the value to a 32-bit integer.
33
- // We must coerce this into a 32-bit unsigned integer.
34
- return hash + 2 ** 31;
35
- }
36
-
37
- /**
38
- * Pauses the execution of the program for a specified time.
39
- * @param ms - The number of milliseconds to pause the program.
40
- * @returns A promise that resolves after the specified number of milliseconds.
41
- */
42
- export async function sleep(ms: number): Promise<void> {
43
- return new Promise((resolve) => setTimeout(resolve, ms));
44
- }
45
-
46
- /**
47
- * Returns a title to use for a gov proposal that adds a new market.
48
- *
49
- * @param ticker ticker symbol for the new market.
50
- * @returns title for the gov proposal.
51
- */
52
- export function getGovAddNewMarketTitle(ticker: string): string {
53
- return `Add ${ticker} perpetual market`;
54
- }
55
-
56
- /**
57
- * Returns a summary to use for a gov proposal that adds a new market.
58
- *
59
- * @param ticker ticker symbol for the new market.
60
- * @param delayBlocks number of blocks to wait before activating the market.
61
- * @returns summary for the gov proposal.
62
- */
63
- export function getGovAddNewMarketSummary(ticker: string, delayBlocks: number): string {
64
- return `Add the x/prices, x/perpetuals and x/clob parameters needed for a ${ticker} perpetual market. Create the market in INITIALIZING status and transition it to ACTIVE status after ${delayBlocks} blocks.`;
65
- }
66
-
67
- export function calculateClockOffsetFromFetchDateHeader(
68
- clientRequestStartTime: number,
69
- serverReportedTime: number,
70
- clientRequestEndTime: number,
71
- ): number {
72
- // use midpoint, so assume that time for request reach server === time for response to reach us
73
- const estimatedLocalTimeAtServerArrival = (clientRequestStartTime + clientRequestEndTime) / 2;
74
-
75
- // we need an offset such that estimatedLocalTimeAtServerArrival + offset = serverReportedTime
76
- const offset = serverReportedTime - estimatedLocalTimeAtServerArrival;
77
-
78
- return Math.floor(offset);
79
- }
80
-
81
- export function getProxyAgent(proxy: AxiosProxyConfig): HttpsProxyAgent<string> {
82
- const auth = proxy.auth ? `${proxy.auth.username}:${proxy.auth.password}@` : '';
83
- return new HttpsProxyAgent(`${proxy.protocol}://${auth}${proxy.host}:${proxy.port}`);
84
- }