@metaflux-dex/client 0.0.3 → 0.0.6

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 (137) 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.js +1 -1
  7. package/dist/faucet.js.map +1 -1
  8. package/dist/index.d.ts +8 -7
  9. package/dist/index.d.ts.map +1 -1
  10. package/dist/index.js +14 -9
  11. package/dist/index.js.map +1 -1
  12. package/dist/native/actions.d.ts +46 -0
  13. package/dist/native/actions.d.ts.map +1 -0
  14. package/dist/native/actions.js +593 -0
  15. package/dist/native/actions.js.map +1 -0
  16. package/dist/native/digest.d.ts +28 -0
  17. package/dist/native/digest.d.ts.map +1 -0
  18. package/dist/{native.js → native/digest.js} +71 -86
  19. package/dist/native/digest.js.map +1 -0
  20. package/dist/native/index.d.ts +3 -0
  21. package/dist/native/index.d.ts.map +1 -0
  22. package/dist/native/index.js +5 -0
  23. package/dist/native/index.js.map +1 -0
  24. package/dist/rest/http.d.ts.map +1 -0
  25. package/dist/rest/http.js.map +1 -0
  26. package/dist/{info.d.ts → rest/info.d.ts} +1 -1
  27. package/dist/rest/info.d.ts.map +1 -0
  28. package/dist/{info.js → rest/info.js} +8 -5
  29. package/dist/rest/info.js.map +1 -0
  30. package/dist/types/account.d.ts +52 -0
  31. package/dist/types/account.d.ts.map +1 -0
  32. package/dist/types/account.js +8 -0
  33. package/dist/types/account.js.map +1 -0
  34. package/dist/types/encrypted.d.ts +8 -0
  35. package/dist/types/encrypted.d.ts.map +1 -0
  36. package/dist/types/encrypted.js +7 -0
  37. package/dist/types/encrypted.js.map +1 -0
  38. package/dist/types/governance.d.ts +11 -0
  39. package/dist/types/governance.d.ts.map +1 -0
  40. package/dist/types/governance.js +7 -0
  41. package/dist/types/governance.js.map +1 -0
  42. package/dist/types/index.d.ts +10 -0
  43. package/dist/types/index.d.ts.map +1 -0
  44. package/dist/types/index.js +6 -0
  45. package/dist/types/index.js.map +1 -0
  46. package/dist/types/info/core.d.ts +97 -0
  47. package/dist/types/info/core.d.ts.map +1 -0
  48. package/dist/types/info/core.js +15 -0
  49. package/dist/types/info/core.js.map +1 -0
  50. package/dist/{info-types.d.ts → types/info/hl-parity.d.ts} +8 -177
  51. package/dist/types/info/hl-parity.d.ts.map +1 -0
  52. package/dist/types/info/hl-parity.js +8 -0
  53. package/dist/types/info/hl-parity.js.map +1 -0
  54. package/dist/types/info/index.d.ts +4 -0
  55. package/dist/types/info/index.d.ts.map +1 -0
  56. package/dist/types/info/index.js +6 -0
  57. package/dist/types/info/index.js.map +1 -0
  58. package/dist/types/info/reads.d.ts +81 -0
  59. package/dist/types/info/reads.d.ts.map +1 -0
  60. package/dist/types/info/reads.js +7 -0
  61. package/dist/types/info/reads.js.map +1 -0
  62. package/dist/types/meta-bridge.d.ts +8 -0
  63. package/dist/types/meta-bridge.d.ts.map +1 -0
  64. package/dist/types/meta-bridge.js +7 -0
  65. package/dist/types/meta-bridge.js.map +1 -0
  66. package/dist/types/spot.d.ts +41 -0
  67. package/dist/types/spot.d.ts.map +1 -0
  68. package/dist/types/spot.js +7 -0
  69. package/dist/types/spot.js.map +1 -0
  70. package/dist/types/staking.d.ts +12 -0
  71. package/dist/types/staking.d.ts.map +1 -0
  72. package/dist/types/staking.js +6 -0
  73. package/dist/types/staking.js.map +1 -0
  74. package/dist/{types.d.ts → types/trading.d.ts} +33 -1
  75. package/dist/types/trading.d.ts.map +1 -0
  76. package/dist/{types.js → types/trading.js} +3 -3
  77. package/dist/types/trading.js.map +1 -0
  78. package/dist/types/twap.d.ts +13 -0
  79. package/dist/types/twap.d.ts.map +1 -0
  80. package/dist/types/twap.js +7 -0
  81. package/dist/types/twap.js.map +1 -0
  82. package/dist/types/vault.d.ts +24 -0
  83. package/dist/types/vault.d.ts.map +1 -0
  84. package/dist/types/vault.js +6 -0
  85. package/dist/types/vault.js.map +1 -0
  86. package/dist/{wasm.d.ts → wallet/wasm.d.ts} +1 -1
  87. package/dist/wallet/wasm.d.ts.map +1 -0
  88. package/dist/{wasm.js → wallet/wasm.js} +9 -8
  89. package/dist/wallet/wasm.js.map +1 -0
  90. package/dist/{ws.d.ts → ws/ws.d.ts} +14 -1
  91. package/dist/ws/ws.d.ts.map +1 -0
  92. package/dist/{ws.js → ws/ws.js} +27 -15
  93. package/dist/ws/ws.js.map +1 -0
  94. package/package.json +3 -1
  95. package/src/client.ts +610 -12
  96. package/src/faucet.ts +1 -1
  97. package/src/index.ts +117 -15
  98. package/src/native/actions.ts +820 -0
  99. package/src/{native.ts → native/digest.ts} +78 -95
  100. package/src/native/index.ts +5 -0
  101. package/src/{http.ts → rest/http.ts} +1 -1
  102. package/src/{info.ts → rest/info.ts} +9 -6
  103. package/src/types/account.ts +111 -0
  104. package/src/types/encrypted.ts +21 -0
  105. package/src/types/governance.ts +27 -0
  106. package/src/types/index.ts +79 -0
  107. package/src/types/info/core.ts +214 -0
  108. package/src/types/info/hl-parity.ts +428 -0
  109. package/src/types/info/index.ts +78 -0
  110. package/src/types/info/reads.ts +165 -0
  111. package/src/types/meta-bridge.ts +22 -0
  112. package/src/types/spot.ts +114 -0
  113. package/src/types/staking.ts +27 -0
  114. package/src/{types.ts → types/trading.ts} +92 -8
  115. package/src/types/twap.ts +29 -0
  116. package/src/types/vault.ts +55 -0
  117. package/src/{wasm.ts → wallet/wasm.ts} +10 -9
  118. package/src/{ws.ts → ws/ws.ts} +75 -22
  119. package/dist/http.d.ts.map +0 -1
  120. package/dist/http.js.map +0 -1
  121. package/dist/info-types.d.ts.map +0 -1
  122. package/dist/info-types.js +0 -16
  123. package/dist/info-types.js.map +0 -1
  124. package/dist/info.d.ts.map +0 -1
  125. package/dist/info.js.map +0 -1
  126. package/dist/native.d.ts +0 -12
  127. package/dist/native.d.ts.map +0 -1
  128. package/dist/native.js.map +0 -1
  129. package/dist/types.d.ts.map +0 -1
  130. package/dist/types.js.map +0 -1
  131. package/dist/wasm.d.ts.map +0 -1
  132. package/dist/wasm.js.map +0 -1
  133. package/dist/ws.d.ts.map +0 -1
  134. package/dist/ws.js.map +0 -1
  135. package/src/info-types.ts +0 -783
  136. /package/dist/{http.d.ts → rest/http.d.ts} +0 -0
  137. /package/dist/{http.js → rest/http.js} +0 -0
@@ -1,8 +1,8 @@
1
- // MTF-native signed-action digest + envelope construction.
1
+ // MTF-native signed-action digest + envelope construction (signing core).
2
2
  //
3
3
  // This is the byte-exact TS twin of the Rust SDK reference
4
4
  // (`metaflux-client-rust/src/rest/exchange.rs::ActionSignedDigest`) and the
5
- // server verifier (`metaflux/crates/core-state/src/signing.rs`).
5
+ // server's native-action signature verifier.
6
6
  //
7
7
  // digest = keccak256(0x1901 || domainSep5 || structHash)
8
8
  // domainSep5 = keccak256(
@@ -16,21 +16,16 @@
16
16
  // CRITICAL: the signature is verified over the EXACT `action` bytes the server
17
17
  // receives (it parses `action` as `serde_json::value::RawValue`). So the same
18
18
  // JSON string MUST be both signed and sent verbatim — never re-stringified
19
- // from a parsed object. `buildNativeOrderAction` is the single source of those
20
- // bytes.
19
+ // from a parsed object. The `build*Action` functions in `./actions.js` are the
20
+ // single source of those bytes.
21
21
 
22
22
  import {
23
23
  deriveAddressFromPubkey,
24
24
  keccak256,
25
25
  recoverPubkey,
26
26
  signSecp256k1,
27
- } from './wasm.js';
28
- import type {
29
- NativeBuilder,
30
- NativeCancel,
31
- NativeOrder,
32
- NativeSignedAction,
33
- } from './types.js';
27
+ } from '../wallet/wasm.js';
28
+ import type { NativeSignedAction } from '../types/index.js';
34
29
 
35
30
  const MTF_DOMAIN_TYPE =
36
31
  'EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)';
@@ -70,7 +65,7 @@ export function nextNonce(): bigint {
70
65
  /// Encode a `bigint` as a 32-byte big-endian buffer (uint256 / nonce slot).
71
66
  /// The value rides in the low bytes; high bytes are zero. Rejects negatives
72
67
  /// and values that overflow 256 bits.
73
- function be32(value: bigint): Uint8Array {
68
+ export function be32(value: bigint): Uint8Array {
74
69
  if (value < 0n) throw new RangeError('be32: value must be non-negative');
75
70
  if (value >= 1n << 256n) throw new RangeError('be32: value overflows uint256');
76
71
  const out = new Uint8Array(32);
@@ -83,7 +78,7 @@ function be32(value: bigint): Uint8Array {
83
78
  }
84
79
 
85
80
  /// Concatenate 32-byte chunks into one buffer.
86
- function concat32(...chunks: Uint8Array[]): Uint8Array {
81
+ export function concat32(...chunks: Uint8Array[]): Uint8Array {
87
82
  const out = new Uint8Array(chunks.length * 32);
88
83
  chunks.forEach((c, i) => {
89
84
  if (c.length !== 32) {
@@ -95,7 +90,7 @@ function concat32(...chunks: Uint8Array[]): Uint8Array {
95
90
  }
96
91
 
97
92
  /// Compute the 5-field MTF-native EIP-712 domain separator.
98
- async function domainSeparator(chainId: number): Promise<Uint8Array> {
93
+ export async function domainSeparator(chainId: number): Promise<Uint8Array> {
99
94
  const typeHash = await keccak256(enc.encode(MTF_DOMAIN_TYPE));
100
95
  const nameHash = await keccak256(enc.encode('MetaFlux'));
101
96
  const versionHash = await keccak256(enc.encode('1'));
@@ -138,7 +133,7 @@ export async function nativeActionDigest(
138
133
  }
139
134
 
140
135
  /// Lowercase hex (no `0x`) of a byte buffer.
141
- function toHex(bytes: Uint8Array): string {
136
+ export function toHex(bytes: Uint8Array): string {
142
137
  let out = '';
143
138
  for (const b of bytes) out += b.toString(16).padStart(2, '0');
144
139
  return out;
@@ -151,84 +146,10 @@ function toHex(bytes: Uint8Array): string {
151
146
  /// / cloids and fixed enum tokens, none of which contain characters needing
152
147
  /// escaping — but we escape defensively so a malformed input can never inject
153
148
  /// raw control bytes into the signed payload.
154
- function jsonStr(s: string): string {
149
+ export function jsonStr(s: string): string {
155
150
  return JSON.stringify(s);
156
151
  }
157
152
 
158
- /// Build the canonical native `submit_order` action JSON string.
159
- ///
160
- /// Field order mirrors the server `NativeOrder` exactly. Optional `cloid` /
161
- /// `builder` are omitted entirely when absent (matching the server's
162
- /// `#[serde(default)]` + KAT vector, where neither appears). The returned
163
- /// string is BOTH what gets signed and what gets sent — do not re-serialize.
164
- export function buildNativeOrderAction(order: NativeOrder): string {
165
- validateAddress(order.owner, 'owner');
166
- validateMarket(order.market);
167
- validateU64(order.size, 'size');
168
- validateU64(order.limit_px, 'limit_px');
169
-
170
- const parts: string[] = [
171
- `${jsonStr('owner')}:${jsonStr(order.owner)}`,
172
- `${jsonStr('market')}:${order.market}`,
173
- `${jsonStr('side')}:${jsonStr(order.side)}`,
174
- `${jsonStr('kind')}:${jsonStr(order.kind)}`,
175
- `${jsonStr('size')}:${order.size}`,
176
- `${jsonStr('limit_px')}:${order.limit_px}`,
177
- `${jsonStr('tif')}:${jsonStr(order.tif)}`,
178
- `${jsonStr('stp_mode')}:${jsonStr(order.stp_mode)}`,
179
- `${jsonStr('reduce_only')}:${order.reduce_only ? 'true' : 'false'}`,
180
- ];
181
- if (order.cloid !== undefined) {
182
- validateCloid(order.cloid);
183
- parts.push(`${jsonStr('cloid')}:${jsonStr(order.cloid)}`);
184
- }
185
- if (order.builder !== undefined) {
186
- parts.push(`${jsonStr('builder')}:${buildBuilder(order.builder)}`);
187
- }
188
- const orderJson = `{${parts.join(',')}}`;
189
- return `{${jsonStr('type')}:${jsonStr('submit_order')},${jsonStr('order')}:${orderJson}}`;
190
- }
191
-
192
- /// Serialize a builder carve in the server-expected `{fee, user}` order.
193
- function buildBuilder(b: NativeBuilder): string {
194
- if (!Number.isInteger(b.fee) || b.fee < 0 || b.fee > 0xffff) {
195
- throw new RangeError('builder.fee must be a u16 (0..=65535)');
196
- }
197
- validateAddress(b.user, 'builder.user');
198
- return `{${jsonStr('fee')}:${b.fee},${jsonStr('user')}:${jsonStr(b.user)}}`;
199
- }
200
-
201
- /// Build the canonical native `cancel_order` action JSON string.
202
- ///
203
- /// Field order mirrors the server `NativeCancel` exactly
204
- /// (`metaflux/crates/api-node/src/rest/native_action.rs`): `owner`, `market`,
205
- /// then `oid` / `cloid` when present. The server's `CancelParams` bridge
206
- /// cancels by `oid`, so an `oid` is REQUIRED for the cancel to lower
207
- /// successfully (a `cloid`-only cancel is accepted on the wire but rejected at
208
- /// lowering with `CancelMissingOid`); we still emit either form so the bytes
209
- /// stay caller-controlled. The returned string is BOTH signed and sent.
210
- export function buildNativeCancelAction(cancel: NativeCancel): string {
211
- validateAddress(cancel.owner, 'owner');
212
- validateMarket(cancel.market);
213
- if (cancel.oid === undefined && cancel.cloid === undefined) {
214
- throw new RangeError('cancel requires an oid (server cancels by oid)');
215
- }
216
- const parts: string[] = [
217
- `${jsonStr('owner')}:${jsonStr(cancel.owner)}`,
218
- `${jsonStr('market')}:${cancel.market}`,
219
- ];
220
- if (cancel.oid !== undefined) {
221
- validateU64(cancel.oid, 'oid');
222
- parts.push(`${jsonStr('oid')}:${cancel.oid}`);
223
- }
224
- if (cancel.cloid !== undefined) {
225
- validateCloid(cancel.cloid);
226
- parts.push(`${jsonStr('cloid')}:${jsonStr(cancel.cloid)}`);
227
- }
228
- const cancelJson = `{${parts.join(',')}}`;
229
- return `{${jsonStr('type')}:${jsonStr('cancel_order')},${jsonStr('cancel')}:${cancelJson}}`;
230
- }
231
-
232
153
  /// Sign a pre-built action JSON string with the given private key.
233
154
  ///
234
155
  /// The returned envelope's `actionJson` is the SAME string passed in — the
@@ -278,27 +199,27 @@ export function nativeRequestBody(signed: NativeSignedAction): string {
278
199
 
279
200
  // ---- validation helpers (fail loud before anything reaches the signed body) ----
280
201
 
281
- function validateAddress(addr: string, field: string): void {
202
+ export function validateAddress(addr: string, field: string): void {
282
203
  const hex = addr.startsWith('0x') ? addr.slice(2) : addr;
283
204
  if (hex.length !== 40 || !/^[0-9a-fA-F]{40}$/.test(hex)) {
284
205
  throw new RangeError(`${field} must be a 0x-prefixed 20-byte hex address`);
285
206
  }
286
207
  }
287
208
 
288
- function validateCloid(cloid: string): void {
209
+ export function validateCloid(cloid: string): void {
289
210
  const hex = cloid.startsWith('0x') ? cloid.slice(2) : cloid;
290
211
  if (hex.length !== 32 || !/^[0-9a-fA-F]{32}$/.test(hex)) {
291
212
  throw new RangeError('cloid must be a 0x-prefixed 16-byte hex string');
292
213
  }
293
214
  }
294
215
 
295
- function validateMarket(market: number): void {
216
+ export function validateMarket(market: number): void {
296
217
  if (!Number.isInteger(market) || market < 0 || market > 0xffffffff) {
297
218
  throw new RangeError('market must be a u32');
298
219
  }
299
220
  }
300
221
 
301
- function validateU64(value: number, field: string): void {
222
+ export function validateU64(value: number, field: string): void {
302
223
  if (!Number.isInteger(value) || value < 0) {
303
224
  throw new RangeError(`${field} must be a non-negative integer`);
304
225
  }
@@ -309,7 +230,69 @@ function validateU64(value: number, field: string): void {
309
230
  }
310
231
  }
311
232
 
312
- function hexToBytes(hex: string): Uint8Array {
233
+ /// Validate a `u32` field passed as a plain `number` (e.g. dst_chain,
234
+ /// window_ms, action-own nonces). Same shape as `validateMarket` but with a
235
+ /// caller-supplied field name for the error message.
236
+ export function validateU32(value: number, field: string): void {
237
+ if (!Number.isInteger(value) || value < 0 || value > 0xffffffff) {
238
+ throw new RangeError(`${field} must be a u32`);
239
+ }
240
+ }
241
+
242
+ /// Validate a `u16` field passed as a plain `number` (e.g. management_fee_bps).
243
+ export function validateU16(value: number, field: string): void {
244
+ if (!Number.isInteger(value) || value < 0 || value > 0xffff) {
245
+ throw new RangeError(`${field} must be a u16 (0..=65535)`);
246
+ }
247
+ }
248
+
249
+ /// Validate a `u8` field passed as a plain `number` (e.g. threshold).
250
+ export function validateU8(value: number, field: string): void {
251
+ if (!Number.isInteger(value) || value < 0 || value > 0xff) {
252
+ throw new RangeError(`${field} must be a u8 (0..=255)`);
253
+ }
254
+ }
255
+
256
+ /// Validate a `u128` field passed as a `bigint`, emitted as a bare unquoted
257
+ /// integer literal on the wire (serde u128 JSON number form). Rejects negatives
258
+ /// and values that overflow 128 bits.
259
+ export function validateU128(value: bigint, field: string): void {
260
+ if (typeof value !== 'bigint') {
261
+ throw new RangeError(`${field} must be a bigint`);
262
+ }
263
+ if (value < 0n) throw new RangeError(`${field} must be non-negative`);
264
+ if (value >= 1n << 128n) throw new RangeError(`${field} overflows u128`);
265
+ }
266
+
267
+ /// Validate a decimal magnitude passed as a string and emitted as a JSON
268
+ /// **string** on the wire (e.g. spot-margin `amount` / `borrow`, Earn
269
+ /// `shares`). The server decodes these as a fixed-point `Decimal`, so they must
270
+ /// be JSON strings to preserve fractional precision past 2^53. Accepts an
271
+ /// optional sign, integer and/or fractional parts; rejects empty / malformed
272
+ /// input and (by default) non-positive values.
273
+ export function validateDecimalString(
274
+ value: string,
275
+ field: string,
276
+ opts: { allowZero?: boolean; allowNegative?: boolean } = {},
277
+ ): void {
278
+ if (typeof value !== 'string') {
279
+ throw new RangeError(`${field} must be a decimal string`);
280
+ }
281
+ if (!/^-?(?:\d+\.?\d*|\.\d+)$/.test(value)) {
282
+ throw new RangeError(`${field} must be a decimal string, got '${value}'`);
283
+ }
284
+ const negative = value.startsWith('-');
285
+ if (negative && !opts.allowNegative) {
286
+ throw new RangeError(`${field} must be non-negative`);
287
+ }
288
+ // Reject a pure-zero magnitude (e.g. "0", "0.0", "-0.00") unless allowed.
289
+ const isZero = /^-?0*\.?0*$/.test(value);
290
+ if (isZero && !opts.allowZero) {
291
+ throw new RangeError(`${field} must be greater than zero`);
292
+ }
293
+ }
294
+
295
+ export function hexToBytes(hex: string): Uint8Array {
313
296
  if (hex.length % 2 !== 0) throw new RangeError('hex length must be even');
314
297
  const out = new Uint8Array(hex.length / 2);
315
298
  for (let i = 0; i < out.length; i++) {
@@ -0,0 +1,5 @@
1
+ // Re-export barrel for the native signed-action surface: the signing core
2
+ // (`digest.ts`) and the canonical action builders (`actions.ts`).
3
+
4
+ export * from './digest.js';
5
+ export * from './actions.js';
@@ -6,7 +6,7 @@
6
6
  // caller has authenticated), and (c) translating the gateway's CCXT-
7
7
  // compat error envelope `{ "error": "..." }` into a typed exception.
8
8
 
9
- import type { ErrorEnvelope } from './types.js';
9
+ import type { ErrorEnvelope } from '../types/index.js';
10
10
 
11
11
  /// Thrown when the gateway responds with a non-2xx status. Carries the
12
12
  /// status code + the message extracted from `{ "error": "..." }` (or
@@ -1,8 +1,7 @@
1
1
  // MTF-native `/info` read API — typed request builders + envelope unwrap.
2
2
  //
3
- // Byte-for-byte mirror of the server dispatcher
4
- // (`metaflux/crates/api-node/src/rest/info.rs::handle_info`) and the per-handler
5
- // shapes in `info/{reads,markets,hl_parity}.rs`. Every request is a
3
+ // Byte-for-byte mirror of the server's `/info` dispatcher and per-handler
4
+ // shapes (per the KB spec metaflux-knowledges/api/rest/info.md). Every request is a
6
5
  // `POST /info` whose body is `{"type": "<discriminator>", ...params}` —
7
6
  // snake_case field names, the exact convention the node decodes. The node's
8
7
  // `/info` surface is MTF-native ONLY; the HL `type` aliases (`meta` etc.) live
@@ -23,7 +22,7 @@
23
22
  // on this surface.
24
23
  //
25
24
  // Money magnitudes that can exceed JS `Number.MAX_SAFE_INTEGER` (2^53) are
26
- // typed `string` in `./info-types.js` to match the node's decimal-string
25
+ // typed `string` in `../types/info/index.js` to match the node's decimal-string
27
26
  // encoding; ids / counts / bps stay `number`.
28
27
 
29
28
  import { httpRequest } from './http.js';
@@ -66,7 +65,7 @@ import type {
66
65
  VaultState,
67
66
  VaultSummaries,
68
67
  WebData2,
69
- } from './info-types.js';
68
+ } from '../types/info/index.js';
70
69
 
71
70
  /// The committed `{type, data}` response envelope every `/info` query returns.
72
71
  interface InfoEnvelope<T> {
@@ -183,7 +182,11 @@ export class InfoApi {
183
182
 
184
183
  // ── HL-node parity reads ────────────────────────────────────────────────
185
184
 
186
- /// `spot_meta` — spot pair universe. No parameters.
185
+ /// `spot_meta` — spot pair universe + token registry. No parameters.
186
+ ///
187
+ /// Each pair's `name` is derived as `{base}/{quote}` from the token
188
+ /// registry; the numeric `id` is the compact `coin` label spot prints carry
189
+ /// on the WS `trades` / `candles` / `fills` channels.
187
190
  async spotMeta(): Promise<SpotMeta> {
188
191
  return this.post<SpotMeta>({ type: 'spot_meta' });
189
192
  }
@@ -0,0 +1,111 @@
1
+ // MTF-native account / margin / agent action payload types.
2
+ //
3
+ // All sender-authorized: the recovered signer is the account whose state
4
+ // mutates, so none carry an `owner` field. Decimal magnitudes (`delta` /
5
+ // `amount` / `value`) ride the wire as JSON strings to preserve precision; ids,
6
+ // leverage, and bps are plain integers.
7
+
8
+ /// `update_leverage` — set the per-asset leverage (and optionally flip to
9
+ /// isolated margin).
10
+ export interface UpdateLeverage {
11
+ /// Target asset / market id (`u32`).
12
+ asset: number;
13
+ /// New leverage multiplier (`u32`, e.g. `10`).
14
+ leverage: number;
15
+ /// `true` also switches the asset to isolated margin.
16
+ is_isolated: boolean;
17
+ }
18
+
19
+ /// `update_isolated_margin` — add or remove isolated margin on an open position.
20
+ export interface UpdateIsolatedMargin {
21
+ /// Target asset / market id (`u32`).
22
+ asset: number;
23
+ /// Signed margin delta as a decimal string (`+` adds, `-` withdraws).
24
+ delta: string;
25
+ }
26
+
27
+ /// `top_up_isolated_only_margin` — top up a strict-isolated-only position.
28
+ export interface TopUpIsolatedOnlyMargin {
29
+ /// Target asset / market id (`u32`).
30
+ asset: number;
31
+ /// Amount to add, as a positive decimal string.
32
+ amount: string;
33
+ }
34
+
35
+ /// `user_portfolio_margin` — enroll into or out of portfolio margin.
36
+ export interface UserPortfolioMargin {
37
+ /// `true` = enroll, `false` = unenroll.
38
+ enroll: boolean;
39
+ }
40
+
41
+ /// `set_display_name` — set the account display name (handle).
42
+ export interface SetDisplayName {
43
+ /// Human-readable handle (e.g. `alice.mtf`).
44
+ display_name: string;
45
+ }
46
+
47
+ /// `set_referrer` — set the account referrer (one-time, immutable once set).
48
+ export interface SetReferrer {
49
+ /// `0x`-hex 20-byte referrer address.
50
+ referrer: string;
51
+ }
52
+
53
+ /// `approve_agent` — approve an agent wallet to sign on behalf of this account.
54
+ export interface ApproveAgent {
55
+ /// `0x`-hex 20-byte agent address.
56
+ agent: string;
57
+ /// Optional human-readable agent label.
58
+ name?: string;
59
+ /// Optional expiry (unix ms). Omit for never-expires.
60
+ expires_at_ms?: number;
61
+ }
62
+
63
+ /// `approve_builder_fee` — approve a builder to charge up to `max_bps` on this
64
+ /// account's orders. `max_bps = 0` revokes.
65
+ export interface ApproveBuilderFee {
66
+ /// `0x`-hex 20-byte builder address.
67
+ builder: string;
68
+ /// Maximum approved fee in basis points (`u16`).
69
+ max_bps: number;
70
+ }
71
+
72
+ /// `convert_to_multi_sig_user` — convert the account to an M-of-N multisig.
73
+ export interface ConvertToMultiSigUser {
74
+ /// `0x`-hex 20-byte authorized signer addresses.
75
+ signers: string[];
76
+ /// Signature threshold `M` of `signers.length` (`u32`).
77
+ threshold: number;
78
+ }
79
+
80
+ /// `user_dex_abstraction` — toggle the account's DEX-abstraction opt-in flag.
81
+ export interface UserDexAbstraction {
82
+ /// `true` = opt in, `false` = opt out.
83
+ enabled: boolean;
84
+ }
85
+
86
+ /// `user_set_abstraction` — set a self-scoped abstraction config value.
87
+ export interface UserSetAbstraction {
88
+ /// Sub-type tag (`u8`, 0..=255); interpretation is config-defined.
89
+ kind: number;
90
+ /// Setting value as a decimal string.
91
+ value: string;
92
+ }
93
+
94
+ /// `agent_set_abstraction` — an approved agent sets an abstraction config value
95
+ /// for `user`. The node verifies the signer is an approved agent of `user`.
96
+ export interface AgentSetAbstraction {
97
+ /// `0x`-hex 20-byte account whose config the agent is updating.
98
+ user: string;
99
+ /// Sub-type tag (`u8`, 0..=255).
100
+ kind: number;
101
+ /// Setting value as a decimal string.
102
+ value: string;
103
+ }
104
+
105
+ /// `priority_bid` — pay a priority fee (bps) for block-front placement.
106
+ export interface PriorityBid {
107
+ /// Asset this bid is bound to (`u32`).
108
+ asset: number;
109
+ /// Bid in basis points (`u16`).
110
+ bid_bps: number;
111
+ }
@@ -0,0 +1,21 @@
1
+ // MTF-native encrypted-order action payload type.
2
+ //
3
+ // Sender-authorized: the recovered signer is the submitter. Decryption shares
4
+ // accumulate over subsequent blocks until `threshold` is met; the order is then
5
+ // revealed (checked against `commitment`) and matched.
6
+
7
+ /// `submit_encrypted_order` — submit a threshold-encrypted order ciphertext.
8
+ export interface SubmitEncryptedOrder {
9
+ /// Ciphertext bytes — emitted as a JSON array of byte numbers.
10
+ ciphertext: Uint8Array;
11
+ /// 32-byte `keccak(plaintext‖salt)` commitment binding the revealed order —
12
+ /// emitted as a JSON array of 32 byte numbers.
13
+ commitment: Uint8Array;
14
+ /// Threshold of decryption shares required to reveal (`u8`, `>= 1`).
15
+ threshold: number;
16
+ /// Earliest block at which the ciphertext can be revealed (`u64`).
17
+ target_block: number;
18
+ /// Deadline (unix ms) by which the order must be revealed, else it expires
19
+ /// (`u64`).
20
+ reveal_deadline_ms: number;
21
+ }
@@ -0,0 +1,27 @@
1
+ // MTF-native governance / operator action payload types.
2
+ //
3
+ // Sender-authorized, with action-level authorization enforced by the node at
4
+ // dispatch: `set_metaliquidity_whitelist` requires validator membership, and
5
+ // `register_metaliquidity_operator` requires the signer to be the vault leader.
6
+
7
+ /// `set_metaliquidity_whitelist` — set an MLP whitelist membership (validator
8
+ /// vote).
9
+ export interface SetMetaliquidityWhitelist {
10
+ /// `0x`-hex 20-byte address whose membership is being set.
11
+ address: string;
12
+ /// `true` adds to the whitelist, `false` removes.
13
+ allowed: boolean;
14
+ }
15
+
16
+ /// `register_metaliquidity_operator` — register or revoke an external strategy
17
+ /// operator for a vault.
18
+ export interface RegisterMetaliquidityOperator {
19
+ /// Target vault id (`u64`).
20
+ vault_id: number;
21
+ /// `0x`-hex 20-byte operator address.
22
+ operator: string;
23
+ /// `true` registers, `false` revokes.
24
+ allowed: boolean;
25
+ /// Optional expiry (unix ms). Omit for never-expires.
26
+ expires_at_ms?: number;
27
+ }
@@ -0,0 +1,79 @@
1
+ // Re-export barrel for every type module.
2
+ //
3
+ // Keeping the type surface behind one barrel means internal modules import from
4
+ // `../types/index.js` and the public `src/index.ts` re-exports from here.
5
+
6
+ export type {
7
+ Order,
8
+ Builder,
9
+ SignedOrder,
10
+ OrderAck,
11
+ Market,
12
+ Position,
13
+ Side,
14
+ Tif,
15
+ StpMode,
16
+ ErrorEnvelope,
17
+ // MTF-native action types.
18
+ NativeOrder,
19
+ NativeCancel,
20
+ NativeBuilder,
21
+ NativeSide,
22
+ NativePositionSide,
23
+ NativeOrderKind,
24
+ NativeTif,
25
+ NativeStpMode,
26
+ NativeSetPositionMode,
27
+ NativeSignedAction,
28
+ NativeExchangeAck,
29
+ OrderStatus,
30
+ // Order-management actions.
31
+ OrderGrouping,
32
+ Modify,
33
+ BatchModify,
34
+ BatchOrder,
35
+ BatchCancel,
36
+ CancelByCloid,
37
+ ScheduleCancel,
38
+ CancelAllOrders,
39
+ } from './trading.js';
40
+ export type {
41
+ NativeSpotOrder,
42
+ NativeSpotCancel,
43
+ NativeSpotMarginDeposit,
44
+ NativeSpotMarginWithdraw,
45
+ NativeSpotMarginOpen,
46
+ NativeSpotMarginClose,
47
+ NativeEarnDeposit,
48
+ NativeEarnWithdraw,
49
+ } from './spot.js';
50
+ export type {
51
+ UpdateLeverage,
52
+ UpdateIsolatedMargin,
53
+ TopUpIsolatedOnlyMargin,
54
+ UserPortfolioMargin,
55
+ SetDisplayName,
56
+ SetReferrer,
57
+ ApproveAgent,
58
+ ApproveBuilderFee,
59
+ ConvertToMultiSigUser,
60
+ UserDexAbstraction,
61
+ UserSetAbstraction,
62
+ AgentSetAbstraction,
63
+ PriorityBid,
64
+ } from './account.js';
65
+ export type { TokenDelegate, ClaimRewards, LinkStakingUser } from './staking.js';
66
+ export type { TwapOrder, TwapCancel } from './twap.js';
67
+ export type {
68
+ SetMetaliquidityWhitelist,
69
+ RegisterMetaliquidityOperator,
70
+ } from './governance.js';
71
+ export type { MbChain, MbWithdraw } from './meta-bridge.js';
72
+ export type {
73
+ VaultKind,
74
+ CreateVault,
75
+ VaultTransfer,
76
+ VaultModify,
77
+ VaultWithdraw,
78
+ } from './vault.js';
79
+ export type { SubmitEncryptedOrder } from './encrypted.js';