@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.
- package/README.md +196 -16
- package/dist/client.d.ts +173 -3
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +264 -11
- package/dist/client.js.map +1 -1
- package/dist/faucet.d.ts +8 -0
- package/dist/faucet.d.ts.map +1 -0
- package/dist/faucet.js +40 -0
- package/dist/faucet.js.map +1 -0
- package/dist/index.d.ts +9 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +15 -9
- package/dist/index.js.map +1 -1
- package/dist/native/actions.d.ts +46 -0
- package/dist/native/actions.d.ts.map +1 -0
- package/dist/native/actions.js +593 -0
- package/dist/native/actions.js.map +1 -0
- package/dist/native/digest.d.ts +28 -0
- package/dist/native/digest.d.ts.map +1 -0
- package/dist/{native.js → native/digest.js} +71 -86
- package/dist/native/digest.js.map +1 -0
- package/dist/native/index.d.ts +3 -0
- package/dist/native/index.d.ts.map +1 -0
- package/dist/native/index.js +5 -0
- package/dist/native/index.js.map +1 -0
- package/dist/rest/http.d.ts.map +1 -0
- package/dist/rest/http.js.map +1 -0
- package/dist/{info.d.ts → rest/info.d.ts} +1 -1
- package/dist/rest/info.d.ts.map +1 -0
- package/dist/{info.js → rest/info.js} +8 -5
- package/dist/rest/info.js.map +1 -0
- package/dist/types/account.d.ts +52 -0
- package/dist/types/account.d.ts.map +1 -0
- package/dist/types/account.js +8 -0
- package/dist/types/account.js.map +1 -0
- package/dist/types/encrypted.d.ts +8 -0
- package/dist/types/encrypted.d.ts.map +1 -0
- package/dist/types/encrypted.js +7 -0
- package/dist/types/encrypted.js.map +1 -0
- package/dist/types/governance.d.ts +11 -0
- package/dist/types/governance.d.ts.map +1 -0
- package/dist/types/governance.js +7 -0
- package/dist/types/governance.js.map +1 -0
- package/dist/types/index.d.ts +10 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +6 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/info/core.d.ts +97 -0
- package/dist/types/info/core.d.ts.map +1 -0
- package/dist/types/info/core.js +15 -0
- package/dist/types/info/core.js.map +1 -0
- package/dist/{info-types.d.ts → types/info/hl-parity.d.ts} +8 -177
- package/dist/types/info/hl-parity.d.ts.map +1 -0
- package/dist/types/info/hl-parity.js +8 -0
- package/dist/types/info/hl-parity.js.map +1 -0
- package/dist/types/info/index.d.ts +4 -0
- package/dist/types/info/index.d.ts.map +1 -0
- package/dist/types/info/index.js +6 -0
- package/dist/types/info/index.js.map +1 -0
- package/dist/types/info/reads.d.ts +81 -0
- package/dist/types/info/reads.d.ts.map +1 -0
- package/dist/types/info/reads.js +7 -0
- package/dist/types/info/reads.js.map +1 -0
- package/dist/types/meta-bridge.d.ts +8 -0
- package/dist/types/meta-bridge.d.ts.map +1 -0
- package/dist/types/meta-bridge.js +7 -0
- package/dist/types/meta-bridge.js.map +1 -0
- package/dist/types/spot.d.ts +41 -0
- package/dist/types/spot.d.ts.map +1 -0
- package/dist/types/spot.js +7 -0
- package/dist/types/spot.js.map +1 -0
- package/dist/types/staking.d.ts +12 -0
- package/dist/types/staking.d.ts.map +1 -0
- package/dist/types/staking.js +6 -0
- package/dist/types/staking.js.map +1 -0
- package/dist/{types.d.ts → types/trading.d.ts} +33 -1
- package/dist/types/trading.d.ts.map +1 -0
- package/dist/{types.js → types/trading.js} +3 -3
- package/dist/types/trading.js.map +1 -0
- package/dist/types/twap.d.ts +13 -0
- package/dist/types/twap.d.ts.map +1 -0
- package/dist/types/twap.js +7 -0
- package/dist/types/twap.js.map +1 -0
- package/dist/types/vault.d.ts +24 -0
- package/dist/types/vault.d.ts.map +1 -0
- package/dist/types/vault.js +6 -0
- package/dist/types/vault.js.map +1 -0
- package/dist/{wasm.d.ts → wallet/wasm.d.ts} +1 -1
- package/dist/wallet/wasm.d.ts.map +1 -0
- package/dist/{wasm.js → wallet/wasm.js} +9 -8
- package/dist/wallet/wasm.js.map +1 -0
- package/dist/{ws.d.ts → ws/ws.d.ts} +1 -1
- package/dist/ws/ws.d.ts.map +1 -0
- package/dist/{ws.js → ws/ws.js} +11 -10
- package/dist/ws/ws.js.map +1 -0
- package/package.json +3 -1
- package/src/client.ts +610 -12
- package/src/faucet.ts +59 -0
- package/src/index.ts +116 -15
- package/src/native/actions.ts +820 -0
- package/src/{native.ts → native/digest.ts} +78 -95
- package/src/native/index.ts +5 -0
- package/src/{http.ts → rest/http.ts} +1 -1
- package/src/{info.ts → rest/info.ts} +9 -6
- package/src/types/account.ts +111 -0
- package/src/types/encrypted.ts +21 -0
- package/src/types/governance.ts +27 -0
- package/src/types/index.ts +79 -0
- package/src/types/info/core.ts +214 -0
- package/src/types/info/hl-parity.ts +428 -0
- package/src/types/info/index.ts +78 -0
- package/src/types/info/reads.ts +165 -0
- package/src/types/meta-bridge.ts +22 -0
- package/src/types/spot.ts +114 -0
- package/src/types/staking.ts +27 -0
- package/src/{types.ts → types/trading.ts} +92 -8
- package/src/types/twap.ts +29 -0
- package/src/types/vault.ts +55 -0
- package/src/{wasm.ts → wallet/wasm.ts} +10 -9
- package/src/{ws.ts → ws/ws.ts} +16 -14
- package/dist/http.d.ts.map +0 -1
- package/dist/http.js.map +0 -1
- package/dist/info-types.d.ts.map +0 -1
- package/dist/info-types.js +0 -16
- package/dist/info-types.js.map +0 -1
- package/dist/info.d.ts.map +0 -1
- package/dist/info.js.map +0 -1
- package/dist/native.d.ts +0 -12
- package/dist/native.d.ts.map +0 -1
- package/dist/native.js.map +0 -1
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js.map +0 -1
- package/dist/wasm.d.ts.map +0 -1
- package/dist/wasm.js.map +0 -1
- package/dist/ws.d.ts.map +0 -1
- package/dist/ws.js.map +0 -1
- package/src/info-types.ts +0 -783
- /package/dist/{http.d.ts → rest/http.d.ts} +0 -0
- /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
|
|
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
|
|
14
|
-
//
|
|
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:
|
|
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
|
|
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
|
-
|
|
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';
|