@0xmonaco/core 0.8.10 → 0.8.11
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 +3 -12
- package/dist/api/market/api.d.ts +2 -1
- package/dist/api/market/api.js +6 -0
- package/dist/api/perp/routes.d.ts +2 -0
- package/dist/api/perp/routes.js +1 -0
- package/dist/api/vault/api.d.ts +26 -2
- package/dist/api/vault/api.js +33 -4
- package/dist/api/vault/index.d.ts +1 -1
- package/dist/api/vault/index.js +1 -1
- package/dist/coverage.d.ts +1 -0
- package/dist/coverage.js +1 -0
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -62,26 +62,17 @@ npm install viem@^2.31.7
|
|
|
62
62
|
|
|
63
63
|
## Network Support
|
|
64
64
|
|
|
65
|
-
The SDK supports the following preset networks. Configure the network by providing the `network` and `seiRpcUrl` parameters:
|
|
65
|
+
The SDK supports the following documented preset networks. Configure the network by providing the `network` and `seiRpcUrl` parameters:
|
|
66
66
|
|
|
67
67
|
**Preset Networks:**
|
|
68
|
-
- `"development"` - Development environment (https://develop.apimonaco.xyz)
|
|
69
68
|
- `"staging"` - Staging environment (https://staging.apimonaco.xyz)
|
|
70
69
|
- `"mainnet"` - Production environment (https://api.monaco.xyz)
|
|
71
|
-
- `"local"` - Local development (http://localhost:8080)
|
|
72
70
|
|
|
73
71
|
WebSocket URLs are automatically resolved per network.
|
|
74
72
|
|
|
75
73
|
```typescript
|
|
76
74
|
import { MonacoSDK } from "@0xmonaco/core";
|
|
77
75
|
|
|
78
|
-
// Development configuration
|
|
79
|
-
const devSdk = new MonacoSDK({
|
|
80
|
-
walletClient,
|
|
81
|
-
network: "development",
|
|
82
|
-
seiRpcUrl: "https://evm-rpc-testnet.sei-apis.com",
|
|
83
|
-
});
|
|
84
|
-
|
|
85
76
|
// Staging configuration
|
|
86
77
|
const stagingSdk = new MonacoSDK({
|
|
87
78
|
walletClient,
|
|
@@ -114,7 +105,7 @@ const walletClient = createWalletClient({
|
|
|
114
105
|
|
|
115
106
|
const monaco = new MonacoSDK({
|
|
116
107
|
walletClient,
|
|
117
|
-
network: "
|
|
108
|
+
network: "staging", // or "mainnet"
|
|
118
109
|
seiRpcUrl: "https://evm-rpc-testnet.sei-apis.com", // or https://evm-rpc.sei-apis.com for mainnet
|
|
119
110
|
});
|
|
120
111
|
|
|
@@ -251,7 +242,7 @@ interface SDKConfig {
|
|
|
251
242
|
/** Wallet client for signing operations (optional - can be set later via setWalletClient) */
|
|
252
243
|
walletClient?: WalletClient;
|
|
253
244
|
|
|
254
|
-
/**
|
|
245
|
+
/** Use "staging" for public testnet or "mainnet" for production. */
|
|
255
246
|
network: Network;
|
|
256
247
|
|
|
257
248
|
/** RPC URL for Sei blockchain interactions */
|
package/dist/api/market/api.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Candlestick, FundingState, GetCandlesticksParams, GetScreenerParams, GetScreenerResponse, GetTradingPairsParams, GetTradingPairsResponse, IndexPrice, Interval, ListFundingHistoryParams, ListFundingHistoryResponse, MarketAPI, MarketMetadata, MarkPrice, OpenInterest, PerpMarketConfig, PerpMarketSummary, TradingPair } from "@0xmonaco/types";
|
|
1
|
+
import type { Candlestick, FundingState, GetCandlesticksParams, GetScreenerParams, GetScreenerResponse, GetTradingPairsParams, GetTradingPairsResponse, IndexPrice, Interval, ListFundingHistoryParams, ListFundingHistoryResponse, MarketAPI, MarketMetadata, MarketStats, MarkPrice, OpenInterest, PerpMarketConfig, PerpMarketSummary, TradingPair } from "@0xmonaco/types";
|
|
2
2
|
import { BaseAPI } from "../base";
|
|
3
3
|
/**
|
|
4
4
|
* Market API Implementation
|
|
@@ -19,4 +19,5 @@ export declare class MarketAPIImpl extends BaseAPI implements MarketAPI {
|
|
|
19
19
|
listFundingHistory(tradingPairId: string, params?: ListFundingHistoryParams): Promise<ListFundingHistoryResponse>;
|
|
20
20
|
getOpenInterest(tradingPairId: string): Promise<OpenInterest>;
|
|
21
21
|
getScreener(params?: GetScreenerParams): Promise<GetScreenerResponse>;
|
|
22
|
+
getMarketStats(): Promise<MarketStats>;
|
|
22
23
|
}
|
package/dist/api/market/api.js
CHANGED
|
@@ -27,6 +27,9 @@ export class MarketAPIImpl extends BaseAPI {
|
|
|
27
27
|
if (params?.is_active !== undefined) {
|
|
28
28
|
searchParams.append("is_active", params.is_active.toString());
|
|
29
29
|
}
|
|
30
|
+
if (params?.category) {
|
|
31
|
+
searchParams.append("category", params.category);
|
|
32
|
+
}
|
|
30
33
|
const queryString = searchParams.toString();
|
|
31
34
|
const url = queryString ? `/api/v1/market/pairs?${queryString}` : "/api/v1/market/pairs";
|
|
32
35
|
return await this.makePublicRequest(url);
|
|
@@ -102,4 +105,7 @@ export class MarketAPIImpl extends BaseAPI {
|
|
|
102
105
|
async getScreener(params) {
|
|
103
106
|
return await this.makePublicRequest(perpRoutes.market.getScreener(params));
|
|
104
107
|
}
|
|
108
|
+
async getMarketStats() {
|
|
109
|
+
return await this.makePublicRequest(perpRoutes.market.getMarketStats());
|
|
110
|
+
}
|
|
105
111
|
}
|
|
@@ -69,7 +69,9 @@ export declare const perpRoutes: {
|
|
|
69
69
|
page_size?: number;
|
|
70
70
|
market_type?: string;
|
|
71
71
|
is_active?: boolean;
|
|
72
|
+
category?: string;
|
|
72
73
|
}) => string;
|
|
74
|
+
readonly getMarketStats: () => string;
|
|
73
75
|
};
|
|
74
76
|
readonly orderbook: {
|
|
75
77
|
readonly get: (tradingPairId: string, params?: {
|
package/dist/api/perp/routes.js
CHANGED
|
@@ -52,6 +52,7 @@ export const perpRoutes = {
|
|
|
52
52
|
listFundingHistory: (tradingPairId, params) => withQuery(`${API_V1}/market/pairs/${encodeSegment(tradingPairId)}/funding/history`, params),
|
|
53
53
|
getOpenInterest: (tradingPairId) => `${API_V1}/market/pairs/${encodeSegment(tradingPairId)}/open-interest`,
|
|
54
54
|
getScreener: (params) => withQuery(`${API_V1}/market/screener`, params),
|
|
55
|
+
getMarketStats: () => `${API_V1}/market/stats`,
|
|
55
56
|
},
|
|
56
57
|
orderbook: {
|
|
57
58
|
get: (tradingPairId, params) => withQuery(`${API_V1}/orderbook/${encodeSegment(tradingPairId)}`, params),
|
package/dist/api/vault/api.d.ts
CHANGED
|
@@ -23,9 +23,21 @@
|
|
|
23
23
|
* console.log(`Deposit transaction: ${result.hash}`);
|
|
24
24
|
* ```
|
|
25
25
|
*/
|
|
26
|
-
import type { ApplicationsAPI, Balance, ProfileAPI, TransactionResult, VaultAPI, WithdrawResult } from "@0xmonaco/types";
|
|
26
|
+
import type { ApplicationsAPI, Balance, DepositTarget, ProfileAPI, TransactionResult, VaultAPI, WithdrawResult } from "@0xmonaco/types";
|
|
27
27
|
import { type Address, type Chain, type PublicClient, type WalletClient } from "viem";
|
|
28
28
|
import { BaseAPI } from "../base";
|
|
29
|
+
/**
|
|
30
|
+
* Encode the on-chain `applicationData` for a deposit.
|
|
31
|
+
*
|
|
32
|
+
* For `"spot"` (the default) this stays the bare `clientId` string — byte-for-byte
|
|
33
|
+
* identical to the legacy encoding, so existing deposits are unchanged. For
|
|
34
|
+
* `"margin"` it emits a small JSON routing hint the indexer decodes to credit the
|
|
35
|
+
* deposit to margin collateral.
|
|
36
|
+
*
|
|
37
|
+
* MUST stay in sync with the indexer decoder in
|
|
38
|
+
* `indexer/src/listeners/deposit_routing.rs`.
|
|
39
|
+
*/
|
|
40
|
+
export declare function encodeDepositApplicationData(clientId: string, target: DepositTarget): string;
|
|
29
41
|
export declare class VaultAPIImpl extends BaseAPI implements VaultAPI {
|
|
30
42
|
private readonly publicClient;
|
|
31
43
|
private readonly chain;
|
|
@@ -121,6 +133,10 @@ export declare class VaultAPIImpl extends BaseAPI implements VaultAPI {
|
|
|
121
133
|
* @param assetId - The asset identifier (UUID) to deposit
|
|
122
134
|
* @param amount - The amount of tokens to deposit (as bigint)
|
|
123
135
|
* @param autoWait - Whether to automatically wait for transaction confirmation (defaults to true)
|
|
136
|
+
* @param target - Destination ledger: `"spot"` (default) credits the spot
|
|
137
|
+
* wallet; `"margin"` routes the deposit into the parent margin account's
|
|
138
|
+
* collateral (auto-creating the account if needed). Margin deposits that
|
|
139
|
+
* cannot be routed safely fall back to spot.
|
|
124
140
|
* @returns Promise resolving to TransactionResult with transaction details
|
|
125
141
|
* @throws {ContractError} When deposit fails or approval is insufficient
|
|
126
142
|
* @throws {APIError} When the asset is not found or the assetId is invalid
|
|
@@ -136,6 +152,14 @@ export declare class VaultAPIImpl extends BaseAPI implements VaultAPI {
|
|
|
136
152
|
* console.log(`Deposit transaction: ${result.hash}`);
|
|
137
153
|
* console.log(`Status: ${result.status}`); // "confirmed" if successful
|
|
138
154
|
*
|
|
155
|
+
* // Deposit straight into margin collateral
|
|
156
|
+
* const marginDeposit = await vaultAPI.deposit(
|
|
157
|
+
* "123e4567-e89b-12d3-a456-426614174000",
|
|
158
|
+
* parseUnits("100", 6),
|
|
159
|
+
* true,
|
|
160
|
+
* "margin"
|
|
161
|
+
* );
|
|
162
|
+
*
|
|
139
163
|
* // Or skip auto-waiting
|
|
140
164
|
* const result = await vaultAPI.deposit(
|
|
141
165
|
* "123e4567-e89b-12d3-a456-426614174000",
|
|
@@ -146,7 +170,7 @@ export declare class VaultAPIImpl extends BaseAPI implements VaultAPI {
|
|
|
146
170
|
* const receipt = await sdk.waitForTransaction(result.hash);
|
|
147
171
|
* ```
|
|
148
172
|
*/
|
|
149
|
-
deposit(assetId: string, amount: bigint, autoWait?: boolean): Promise<TransactionResult>;
|
|
173
|
+
deposit(assetId: string, amount: bigint, autoWait?: boolean, target?: DepositTarget): Promise<TransactionResult>;
|
|
150
174
|
/**
|
|
151
175
|
* Initiates a withdrawal through the API Gateway and submits the resulting
|
|
152
176
|
* pre-signed calldata on-chain via the connected wallet.
|
package/dist/api/vault/api.js
CHANGED
|
@@ -28,6 +28,20 @@ import { ApproveTokenSchema, DepositSchema, validate, WithdrawSchema } from "@0x
|
|
|
28
28
|
import { erc20Abi, zeroAddress } from "viem";
|
|
29
29
|
import { APIError, ContractError, InvalidConfigError } from "../../errors";
|
|
30
30
|
import { BaseAPI } from "../base";
|
|
31
|
+
/**
|
|
32
|
+
* Encode the on-chain `applicationData` for a deposit.
|
|
33
|
+
*
|
|
34
|
+
* For `"spot"` (the default) this stays the bare `clientId` string — byte-for-byte
|
|
35
|
+
* identical to the legacy encoding, so existing deposits are unchanged. For
|
|
36
|
+
* `"margin"` it emits a small JSON routing hint the indexer decodes to credit the
|
|
37
|
+
* deposit to margin collateral.
|
|
38
|
+
*
|
|
39
|
+
* MUST stay in sync with the indexer decoder in
|
|
40
|
+
* `indexer/src/listeners/deposit_routing.rs`.
|
|
41
|
+
*/
|
|
42
|
+
export function encodeDepositApplicationData(clientId, target) {
|
|
43
|
+
return target === "margin" ? JSON.stringify({ clientId, depositTarget: "MARGIN" }) : clientId;
|
|
44
|
+
}
|
|
31
45
|
export class VaultAPIImpl extends BaseAPI {
|
|
32
46
|
publicClient;
|
|
33
47
|
chain;
|
|
@@ -196,6 +210,10 @@ export class VaultAPIImpl extends BaseAPI {
|
|
|
196
210
|
* @param assetId - The asset identifier (UUID) to deposit
|
|
197
211
|
* @param amount - The amount of tokens to deposit (as bigint)
|
|
198
212
|
* @param autoWait - Whether to automatically wait for transaction confirmation (defaults to true)
|
|
213
|
+
* @param target - Destination ledger: `"spot"` (default) credits the spot
|
|
214
|
+
* wallet; `"margin"` routes the deposit into the parent margin account's
|
|
215
|
+
* collateral (auto-creating the account if needed). Margin deposits that
|
|
216
|
+
* cannot be routed safely fall back to spot.
|
|
199
217
|
* @returns Promise resolving to TransactionResult with transaction details
|
|
200
218
|
* @throws {ContractError} When deposit fails or approval is insufficient
|
|
201
219
|
* @throws {APIError} When the asset is not found or the assetId is invalid
|
|
@@ -211,6 +229,14 @@ export class VaultAPIImpl extends BaseAPI {
|
|
|
211
229
|
* console.log(`Deposit transaction: ${result.hash}`);
|
|
212
230
|
* console.log(`Status: ${result.status}`); // "confirmed" if successful
|
|
213
231
|
*
|
|
232
|
+
* // Deposit straight into margin collateral
|
|
233
|
+
* const marginDeposit = await vaultAPI.deposit(
|
|
234
|
+
* "123e4567-e89b-12d3-a456-426614174000",
|
|
235
|
+
* parseUnits("100", 6),
|
|
236
|
+
* true,
|
|
237
|
+
* "margin"
|
|
238
|
+
* );
|
|
239
|
+
*
|
|
214
240
|
* // Or skip auto-waiting
|
|
215
241
|
* const result = await vaultAPI.deposit(
|
|
216
242
|
* "123e4567-e89b-12d3-a456-426614174000",
|
|
@@ -221,14 +247,17 @@ export class VaultAPIImpl extends BaseAPI {
|
|
|
221
247
|
* const receipt = await sdk.waitForTransaction(result.hash);
|
|
222
248
|
* ```
|
|
223
249
|
*/
|
|
224
|
-
async deposit(assetId, amount, autoWait = true) {
|
|
250
|
+
async deposit(assetId, amount, autoWait = true, target = "spot") {
|
|
225
251
|
if (!this.walletClient) {
|
|
226
252
|
throw new InvalidConfigError("Wallet client not set. Connect a wallet first.", "walletClient");
|
|
227
253
|
}
|
|
228
254
|
// Validate inputs
|
|
229
|
-
validate(DepositSchema, { assetId, amount, autoWait });
|
|
255
|
+
validate(DepositSchema, { assetId, amount, autoWait, target });
|
|
230
256
|
const vaultAddress = await this.getVaultAddress();
|
|
231
257
|
const clientId = await this.getClientId();
|
|
258
|
+
// The on-chain applicationData carries the client id plus, for margin
|
|
259
|
+
// deposits, the routing hint the indexer decodes.
|
|
260
|
+
const applicationData = encodeDepositApplicationData(clientId, target);
|
|
232
261
|
const { tokenAddress, isNativeToken } = await this.resolveAsset(assetId);
|
|
233
262
|
if (!isNativeToken) {
|
|
234
263
|
// Check if approval is needed before proceeding
|
|
@@ -250,7 +279,7 @@ export class VaultAPIImpl extends BaseAPI {
|
|
|
250
279
|
address: vaultAddress,
|
|
251
280
|
abi: CONTRACT_ABIS.vault,
|
|
252
281
|
functionName: "depositNative",
|
|
253
|
-
args: [walletAccount.address,
|
|
282
|
+
args: [walletAccount.address, applicationData],
|
|
254
283
|
account: walletAccount,
|
|
255
284
|
chain: this.chain,
|
|
256
285
|
value: amount,
|
|
@@ -261,7 +290,7 @@ export class VaultAPIImpl extends BaseAPI {
|
|
|
261
290
|
address: vaultAddress,
|
|
262
291
|
abi: CONTRACT_ABIS.vault,
|
|
263
292
|
functionName: "depositERC20",
|
|
264
|
-
args: [walletAccount.address,
|
|
293
|
+
args: [walletAccount.address, applicationData, tokenAddress, amount],
|
|
265
294
|
account: walletAccount,
|
|
266
295
|
chain: this.chain,
|
|
267
296
|
});
|
package/dist/api/vault/index.js
CHANGED
package/dist/coverage.d.ts
CHANGED
package/dist/coverage.js
CHANGED
|
@@ -25,6 +25,7 @@ export const COVERED = {
|
|
|
25
25
|
get_margin_account_summary: "getMarginAccountSummary",
|
|
26
26
|
get_mark_price: "getMarkPrice",
|
|
27
27
|
get_market_metadata: "getMarketMetadata",
|
|
28
|
+
get_market_stats: "getMarketStats",
|
|
28
29
|
get_open_interest: "getOpenInterest",
|
|
29
30
|
get_order_by_id: "getOrder",
|
|
30
31
|
get_orderbook_snapshot: "getOrderbook",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@0xmonaco/core",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.11",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -23,8 +23,8 @@
|
|
|
23
23
|
"viem": "^2.45.2"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@0xmonaco/contracts": "0.8.
|
|
27
|
-
"@0xmonaco/types": "0.8.
|
|
26
|
+
"@0xmonaco/contracts": "0.8.11",
|
|
27
|
+
"@0xmonaco/types": "0.8.11",
|
|
28
28
|
"@noble/curves": "^1.9.1",
|
|
29
29
|
"@noble/hashes": "^1.8.0",
|
|
30
30
|
"http-status-codes": "^2.3.0"
|