@metaflux-dex/client 0.0.2 → 0.0.5

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 (139) hide show
  1. package/README.md +196 -16
  2. package/dist/client.d.ts +173 -3
  3. package/dist/client.d.ts.map +1 -1
  4. package/dist/client.js +264 -11
  5. package/dist/client.js.map +1 -1
  6. package/dist/faucet.d.ts +8 -0
  7. package/dist/faucet.d.ts.map +1 -0
  8. package/dist/faucet.js +40 -0
  9. package/dist/faucet.js.map +1 -0
  10. package/dist/index.d.ts +9 -7
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +15 -9
  13. package/dist/index.js.map +1 -1
  14. package/dist/native/actions.d.ts +46 -0
  15. package/dist/native/actions.d.ts.map +1 -0
  16. package/dist/native/actions.js +593 -0
  17. package/dist/native/actions.js.map +1 -0
  18. package/dist/native/digest.d.ts +28 -0
  19. package/dist/native/digest.d.ts.map +1 -0
  20. package/dist/{native.js → native/digest.js} +71 -86
  21. package/dist/native/digest.js.map +1 -0
  22. package/dist/native/index.d.ts +3 -0
  23. package/dist/native/index.d.ts.map +1 -0
  24. package/dist/native/index.js +5 -0
  25. package/dist/native/index.js.map +1 -0
  26. package/dist/rest/http.d.ts.map +1 -0
  27. package/dist/rest/http.js.map +1 -0
  28. package/dist/{info.d.ts → rest/info.d.ts} +1 -1
  29. package/dist/rest/info.d.ts.map +1 -0
  30. package/dist/{info.js → rest/info.js} +8 -5
  31. package/dist/rest/info.js.map +1 -0
  32. package/dist/types/account.d.ts +52 -0
  33. package/dist/types/account.d.ts.map +1 -0
  34. package/dist/types/account.js +8 -0
  35. package/dist/types/account.js.map +1 -0
  36. package/dist/types/encrypted.d.ts +8 -0
  37. package/dist/types/encrypted.d.ts.map +1 -0
  38. package/dist/types/encrypted.js +7 -0
  39. package/dist/types/encrypted.js.map +1 -0
  40. package/dist/types/governance.d.ts +11 -0
  41. package/dist/types/governance.d.ts.map +1 -0
  42. package/dist/types/governance.js +7 -0
  43. package/dist/types/governance.js.map +1 -0
  44. package/dist/types/index.d.ts +10 -0
  45. package/dist/types/index.d.ts.map +1 -0
  46. package/dist/types/index.js +6 -0
  47. package/dist/types/index.js.map +1 -0
  48. package/dist/types/info/core.d.ts +97 -0
  49. package/dist/types/info/core.d.ts.map +1 -0
  50. package/dist/types/info/core.js +15 -0
  51. package/dist/types/info/core.js.map +1 -0
  52. package/dist/{info-types.d.ts → types/info/hl-parity.d.ts} +8 -177
  53. package/dist/types/info/hl-parity.d.ts.map +1 -0
  54. package/dist/types/info/hl-parity.js +8 -0
  55. package/dist/types/info/hl-parity.js.map +1 -0
  56. package/dist/types/info/index.d.ts +4 -0
  57. package/dist/types/info/index.d.ts.map +1 -0
  58. package/dist/types/info/index.js +6 -0
  59. package/dist/types/info/index.js.map +1 -0
  60. package/dist/types/info/reads.d.ts +81 -0
  61. package/dist/types/info/reads.d.ts.map +1 -0
  62. package/dist/types/info/reads.js +7 -0
  63. package/dist/types/info/reads.js.map +1 -0
  64. package/dist/types/meta-bridge.d.ts +8 -0
  65. package/dist/types/meta-bridge.d.ts.map +1 -0
  66. package/dist/types/meta-bridge.js +7 -0
  67. package/dist/types/meta-bridge.js.map +1 -0
  68. package/dist/types/spot.d.ts +41 -0
  69. package/dist/types/spot.d.ts.map +1 -0
  70. package/dist/types/spot.js +7 -0
  71. package/dist/types/spot.js.map +1 -0
  72. package/dist/types/staking.d.ts +12 -0
  73. package/dist/types/staking.d.ts.map +1 -0
  74. package/dist/types/staking.js +6 -0
  75. package/dist/types/staking.js.map +1 -0
  76. package/dist/{types.d.ts → types/trading.d.ts} +33 -1
  77. package/dist/types/trading.d.ts.map +1 -0
  78. package/dist/{types.js → types/trading.js} +3 -3
  79. package/dist/types/trading.js.map +1 -0
  80. package/dist/types/twap.d.ts +13 -0
  81. package/dist/types/twap.d.ts.map +1 -0
  82. package/dist/types/twap.js +7 -0
  83. package/dist/types/twap.js.map +1 -0
  84. package/dist/types/vault.d.ts +24 -0
  85. package/dist/types/vault.d.ts.map +1 -0
  86. package/dist/types/vault.js +6 -0
  87. package/dist/types/vault.js.map +1 -0
  88. package/dist/{wasm.d.ts → wallet/wasm.d.ts} +1 -1
  89. package/dist/wallet/wasm.d.ts.map +1 -0
  90. package/dist/{wasm.js → wallet/wasm.js} +9 -8
  91. package/dist/wallet/wasm.js.map +1 -0
  92. package/dist/{ws.d.ts → ws/ws.d.ts} +1 -1
  93. package/dist/ws/ws.d.ts.map +1 -0
  94. package/dist/{ws.js → ws/ws.js} +11 -10
  95. package/dist/ws/ws.js.map +1 -0
  96. package/package.json +3 -1
  97. package/src/client.ts +610 -12
  98. package/src/faucet.ts +59 -0
  99. package/src/index.ts +116 -15
  100. package/src/native/actions.ts +820 -0
  101. package/src/{native.ts → native/digest.ts} +78 -95
  102. package/src/native/index.ts +5 -0
  103. package/src/{http.ts → rest/http.ts} +1 -1
  104. package/src/{info.ts → rest/info.ts} +9 -6
  105. package/src/types/account.ts +111 -0
  106. package/src/types/encrypted.ts +21 -0
  107. package/src/types/governance.ts +27 -0
  108. package/src/types/index.ts +79 -0
  109. package/src/types/info/core.ts +214 -0
  110. package/src/types/info/hl-parity.ts +428 -0
  111. package/src/types/info/index.ts +78 -0
  112. package/src/types/info/reads.ts +165 -0
  113. package/src/types/meta-bridge.ts +22 -0
  114. package/src/types/spot.ts +114 -0
  115. package/src/types/staking.ts +27 -0
  116. package/src/{types.ts → types/trading.ts} +92 -8
  117. package/src/types/twap.ts +29 -0
  118. package/src/types/vault.ts +55 -0
  119. package/src/{wasm.ts → wallet/wasm.ts} +10 -9
  120. package/src/{ws.ts → ws/ws.ts} +16 -14
  121. package/dist/http.d.ts.map +0 -1
  122. package/dist/http.js.map +0 -1
  123. package/dist/info-types.d.ts.map +0 -1
  124. package/dist/info-types.js +0 -16
  125. package/dist/info-types.js.map +0 -1
  126. package/dist/info.d.ts.map +0 -1
  127. package/dist/info.js.map +0 -1
  128. package/dist/native.d.ts +0 -12
  129. package/dist/native.d.ts.map +0 -1
  130. package/dist/native.js.map +0 -1
  131. package/dist/types.d.ts.map +0 -1
  132. package/dist/types.js.map +0 -1
  133. package/dist/wasm.d.ts.map +0 -1
  134. package/dist/wasm.js.map +0 -1
  135. package/dist/ws.d.ts.map +0 -1
  136. package/dist/ws.js.map +0 -1
  137. package/src/info-types.ts +0 -783
  138. /package/dist/{http.d.ts → rest/http.d.ts} +0 -0
  139. /package/dist/{http.js → rest/http.js} +0 -0
package/src/faucet.ts ADDED
@@ -0,0 +1,59 @@
1
+ // Devnet / testnet faucet helper.
2
+ //
3
+ // The node exposes a faucet at `POST <faucetBaseUrl>/faucet` that credits an
4
+ // address with test USDC + MTF. It runs on its OWN origin (devnet node port 8080;
5
+ // production `https://faucet.devnet.mtf.exchange`), SEPARATE from the trading
6
+ // API base URL — so `requestFaucet` takes a dedicated `faucetBaseUrl` rather
7
+ // than reusing a `Client`'s trading base URL.
8
+ //
9
+ // The grant is staged for the NEXT block: a 200 response carries
10
+ // `status: "queued"` and the credited balance lands after ~1 block, not
11
+ // synchronously. Devnet / testnet only — mainnet refuses (surfaced as a
12
+ // `MetaFluxApiError`).
13
+
14
+ import { httpRequest } from './rest/http.js';
15
+
16
+ /// Successful faucet response (200). `status` is `"queued"` — the credit is
17
+ /// staged for the next block, so the balance updates after ~1 block rather
18
+ /// than synchronously.
19
+ export interface FaucetResponse {
20
+ /// Echo of the credited address (`0x`-prefixed 20-byte hex).
21
+ address: string;
22
+ /// Whole-USDC cross-collateral granted (capped server-side, default 3000).
23
+ usdc: number;
24
+ /// MTF spot tokens granted (fixed, default 10).
25
+ mtf: number;
26
+ /// Always `"queued"` — credit staged for the next block.
27
+ status: string;
28
+ }
29
+
30
+ /// Request test USDC from a devnet / testnet faucet.
31
+ ///
32
+ /// POSTs `{ address, amount? }` to `<faucetBaseUrl>/faucet` (grants both USDC and MTF). `amount` is a
33
+ /// whole-USDC integer; omit it for the faucet's full default grant (capped
34
+ /// server-side).
35
+ ///
36
+ /// `faucetBaseUrl` is the faucet's OWN origin (e.g. `http://localhost:8080`
37
+ /// on devnet, `https://faucet.devnet.mtf.exchange` in production) — NOT the
38
+ /// trading API base URL.
39
+ ///
40
+ /// On success the credit is `"queued"` for the next block; the balance updates
41
+ /// after ~1 block, not synchronously.
42
+ ///
43
+ /// Throws `MetaFluxApiError` on a non-2xx status, surfacing the server's
44
+ /// `{ error }` message — notably 429 (rate-limited: per-address once-ever, per-IP
45
+ /// 1/minute), 400 (bad/zero address), 503 (backlog full), or a mainnet refusal.
46
+ export async function requestFaucet(
47
+ faucetBaseUrl: string,
48
+ address: string,
49
+ amount?: number,
50
+ ): Promise<FaucetResponse> {
51
+ const json: { address: string; amount?: number } = { address };
52
+ if (amount !== undefined) {
53
+ json.amount = amount;
54
+ }
55
+ return httpRequest<FaucetResponse>(faucetBaseUrl, '/faucet', {
56
+ method: 'POST',
57
+ json,
58
+ });
59
+ }
package/src/index.ts CHANGED
@@ -1,35 +1,81 @@
1
1
  // Public barrel — every export consumers see goes through this file.
2
2
  //
3
3
  // Pinning the public surface here means we can refactor the internal
4
- // `client.ts` / `wasm.ts` / `http.ts` split without touching anything
5
- // import-facing. The npm package `exports` map points at the compiled
4
+ // `client.ts` / `wallet/wasm.ts` / `rest/http.ts` split without touching
5
+ // anything import-facing. The npm package `exports` map points at the compiled
6
6
  // `dist/index.js`, so consumers write:
7
7
  //
8
8
  // import { Client, type Order } from '@metaflux-dex/client';
9
9
 
10
10
  export { Client, type ClientOpts } from './client.js';
11
- export { MetaFluxApiError } from './http.js';
11
+ export { MetaFluxApiError } from './rest/http.js';
12
+ export { requestFaucet, type FaucetResponse } from './faucet.js';
12
13
  export {
13
- // MTF-native signed-action surface (the path the server now accepts).
14
- // Exported so power users can build / sign / inspect actions out-of-band.
14
+ // MTF-native signed-action signing core. Exported so power users can build /
15
+ // sign / inspect actions out-of-band.
15
16
  MTF_CHAIN_ID,
16
17
  MTF_MAINNET_CHAIN_ID,
17
18
  MTF_TESTNET_CHAIN_ID,
18
19
  nativeActionDigest,
19
- buildNativeOrderAction,
20
- buildNativeCancelAction,
21
20
  signNativeAction,
22
21
  recoverNativeSigner,
23
22
  nativeRequestBody,
24
- } from './native.js';
23
+ } from './native/digest.js';
24
+ export {
25
+ // MTF-native action builders — the full real /exchange surface.
26
+ buildNativeOrderAction,
27
+ buildNativeCancelAction,
28
+ buildNativeCancelByCloidAction,
29
+ buildNativeModifyAction,
30
+ buildNativeBatchModifyAction,
31
+ buildNativeBatchOrderAction,
32
+ buildNativeBatchCancelAction,
33
+ buildNativeScheduleCancelAction,
34
+ buildNativeCancelAllOrdersAction,
35
+ buildNativeSetPositionModeAction,
36
+ buildNativeTwapOrderAction,
37
+ buildNativeTwapCancelAction,
38
+ buildNativeUpdateLeverageAction,
39
+ buildNativeUpdateIsolatedMarginAction,
40
+ buildNativeTopUpIsolatedOnlyMarginAction,
41
+ buildNativeUserPortfolioMarginAction,
42
+ buildNativeSetDisplayNameAction,
43
+ buildNativeSetReferrerAction,
44
+ buildNativeApproveAgentAction,
45
+ buildNativeApproveBuilderFeeAction,
46
+ buildNativeConvertToMultiSigUserAction,
47
+ buildNativeUserDexAbstractionAction,
48
+ buildNativeUserSetAbstractionAction,
49
+ buildNativeAgentSetAbstractionAction,
50
+ buildNativePriorityBidAction,
51
+ buildNativeTokenDelegateAction,
52
+ buildNativeClaimRewardsAction,
53
+ buildNativeLinkStakingUserAction,
54
+ buildNativeSubmitEncryptedOrderAction,
55
+ buildNativeCreateVaultAction,
56
+ buildNativeVaultTransferAction,
57
+ buildNativeVaultModifyAction,
58
+ buildNativeVaultWithdrawAction,
59
+ buildNativeMbWithdrawAction,
60
+ buildNativeSetMetaliquidityWhitelistAction,
61
+ buildNativeRegisterMetaliquidityOperatorAction,
62
+ // Spot CLOB + spot margin (leveraged spot) + Earn (lending pool).
63
+ buildNativeSpotOrderAction,
64
+ buildNativeSpotCancelAction,
65
+ buildNativeSpotMarginDepositAction,
66
+ buildNativeSpotMarginWithdrawAction,
67
+ buildNativeSpotMarginOpenAction,
68
+ buildNativeSpotMarginCloseAction,
69
+ buildNativeEarnDepositAction,
70
+ buildNativeEarnWithdrawAction,
71
+ } from './native/actions.js';
25
72
  export {
26
73
  // MTF-native `/info` read API + the account-ref union (address | account_id).
27
74
  InfoApi,
28
75
  type AccountRef,
29
- } from './info.js';
76
+ } from './rest/info.js';
30
77
  export type {
31
- // MTF-native `/info` response shapes. Source of truth: the node handlers in
32
- // `metaflux/crates/api-node/src/rest/info/{reads,markets,hl_parity}.rs` and
78
+ // MTF-native `/info` response shapes. Source of truth:
33
79
  // the KB spec `metaflux-knowledges/api/rest/info.md`. Every field is the exact
34
80
  // snake_case key the node emits inside the `{type, data}` envelope's `data`.
35
81
  NodeInfo,
@@ -64,6 +110,7 @@ export type {
64
110
  // HL-node parity shapes.
65
111
  SpotMeta,
66
112
  SpotPair,
113
+ SpotToken,
67
114
  SpotClearinghouseState,
68
115
  SpotBalance,
69
116
  ExchangeStatus,
@@ -99,7 +146,7 @@ export type {
99
146
  WebData2,
100
147
  WebData2Clearinghouse,
101
148
  WebData2Position,
102
- } from './info-types.js';
149
+ } from './types/info/index.js';
103
150
  export {
104
151
  // MTF-native WebSocket client + subscription/channel types.
105
152
  WsClient,
@@ -109,7 +156,7 @@ export {
109
156
  type WsFrame,
110
157
  type WsMessageHandler,
111
158
  type WsConfig,
112
- } from './ws.js';
159
+ } from './ws/ws.js';
113
160
  export {
114
161
  WasmNotBuiltError,
115
162
  WasmCallError,
@@ -122,7 +169,7 @@ export {
122
169
  eip712TypedDataHash,
123
170
  encodeLimitOrder,
124
171
  deriveAddressFromPubkey,
125
- } from './wasm.js';
172
+ } from './wallet/wasm.js';
126
173
  export type {
127
174
  Order,
128
175
  Builder,
@@ -138,9 +185,63 @@ export type {
138
185
  NativeCancel,
139
186
  NativeBuilder,
140
187
  NativeSide,
188
+ NativePositionSide,
141
189
  NativeOrderKind,
142
190
  NativeTif,
143
191
  NativeStpMode,
192
+ NativeSetPositionMode,
193
+ NativeSpotOrder,
194
+ NativeSpotCancel,
195
+ NativeSpotMarginDeposit,
196
+ NativeSpotMarginWithdraw,
197
+ NativeSpotMarginOpen,
198
+ NativeSpotMarginClose,
199
+ NativeEarnDeposit,
200
+ NativeEarnWithdraw,
144
201
  NativeSignedAction,
145
202
  NativeExchangeAck,
146
- } from './types.js';
203
+ // Order-management actions.
204
+ OrderGrouping,
205
+ Modify,
206
+ BatchModify,
207
+ BatchOrder,
208
+ BatchCancel,
209
+ CancelByCloid,
210
+ ScheduleCancel,
211
+ CancelAllOrders,
212
+ // Account / margin / agent actions.
213
+ UpdateLeverage,
214
+ UpdateIsolatedMargin,
215
+ TopUpIsolatedOnlyMargin,
216
+ UserPortfolioMargin,
217
+ SetDisplayName,
218
+ SetReferrer,
219
+ ApproveAgent,
220
+ ApproveBuilderFee,
221
+ ConvertToMultiSigUser,
222
+ UserDexAbstraction,
223
+ UserSetAbstraction,
224
+ AgentSetAbstraction,
225
+ PriorityBid,
226
+ // TWAP.
227
+ TwapOrder,
228
+ TwapCancel,
229
+ // Staking.
230
+ TokenDelegate,
231
+ ClaimRewards,
232
+ LinkStakingUser,
233
+ // Encrypted orders.
234
+ SubmitEncryptedOrder,
235
+ // Vaults.
236
+ VaultKind,
237
+ CreateVault,
238
+ VaultTransfer,
239
+ VaultModify,
240
+ VaultWithdraw,
241
+ // MetaBridge.
242
+ MbChain,
243
+ MbWithdraw,
244
+ // Governance / operator.
245
+ SetMetaliquidityWhitelist,
246
+ RegisterMetaliquidityOperator,
247
+ } from './types/index.js';