@0xmonaco/types 0.1.0
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 +260 -0
- package/dist/auth/index.d.ts +90 -0
- package/dist/auth/index.d.ts.map +1 -0
- package/dist/auth/index.js +8 -0
- package/dist/auth/index.js.map +1 -0
- package/dist/auth/responses.d.ts +66 -0
- package/dist/auth/responses.d.ts.map +1 -0
- package/dist/auth/responses.js +7 -0
- package/dist/auth/responses.js.map +1 -0
- package/dist/contracts/balances.d.ts +44 -0
- package/dist/contracts/balances.d.ts.map +1 -0
- package/dist/contracts/balances.js +7 -0
- package/dist/contracts/balances.js.map +1 -0
- package/dist/contracts/index.d.ts +28 -0
- package/dist/contracts/index.d.ts.map +1 -0
- package/dist/contracts/index.js +7 -0
- package/dist/contracts/index.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -0
- package/dist/sdk/index.d.ts +71 -0
- package/dist/sdk/index.d.ts.map +1 -0
- package/dist/sdk/index.js +7 -0
- package/dist/sdk/index.js.map +1 -0
- package/dist/sdk/network.d.ts +21 -0
- package/dist/sdk/network.d.ts.map +1 -0
- package/dist/sdk/network.js +7 -0
- package/dist/sdk/network.js.map +1 -0
- package/dist/trading/index.d.ts +65 -0
- package/dist/trading/index.d.ts.map +1 -0
- package/dist/trading/index.js +7 -0
- package/dist/trading/index.js.map +1 -0
- package/dist/trading/orders.d.ts +22 -0
- package/dist/trading/orders.d.ts.map +1 -0
- package/dist/trading/orders.js +7 -0
- package/dist/trading/orders.js.map +1 -0
- package/dist/trading/responses.d.ts +73 -0
- package/dist/trading/responses.d.ts.map +1 -0
- package/dist/trading/responses.js +7 -0
- package/dist/trading/responses.js.map +1 -0
- package/dist/vault/index.d.ts +60 -0
- package/dist/vault/index.d.ts.map +1 -0
- package/dist/vault/index.js +7 -0
- package/dist/vault/index.js.map +1 -0
- package/dist/vault/responses.d.ts +32 -0
- package/dist/vault/responses.d.ts.map +1 -0
- package/dist/vault/responses.js +7 -0
- package/dist/vault/responses.js.map +1 -0
- package/package.json +29 -0
package/README.md
ADDED
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
# @0xmonaco/types
|
|
2
|
+
|
|
3
|
+
Core type definitions for the Monaco protocol. This package provides TypeScript types and interfaces used throughout the Monaco ecosystem, focusing on SDK configuration, vault operations, trading operations, and contract management.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @0xmonaco/types
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Type Categories
|
|
12
|
+
|
|
13
|
+
### SDK Types
|
|
14
|
+
|
|
15
|
+
Core SDK configuration and main interface types:
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
import { MonacoSDK, SDKConfig } from "@0xmonaco/types";
|
|
19
|
+
|
|
20
|
+
// SDK configuration
|
|
21
|
+
interface SDKConfig {
|
|
22
|
+
privateKey?: Hex; // Private key as hex string (0x-prefixed)
|
|
23
|
+
signer?: PrivateKeyAccount; // Viem Account for advanced account management
|
|
24
|
+
account?: Account; // Custom Account implementation
|
|
25
|
+
network?: Network; // Network override (defaults to 'mainnet')
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Main SDK interface
|
|
29
|
+
interface MonacoSDK {
|
|
30
|
+
vault: VaultAPI; // Vault operations API
|
|
31
|
+
trading: TradingAPI; // Trading operations API
|
|
32
|
+
walletClient: WalletClient; // Wallet client for blockchain operations
|
|
33
|
+
publicClient: PublicClient; // Public client for read-only operations
|
|
34
|
+
|
|
35
|
+
// Account management
|
|
36
|
+
isConnected(): boolean;
|
|
37
|
+
getAccountAddress(): string;
|
|
38
|
+
getNetwork(): Network;
|
|
39
|
+
getChainId(): number;
|
|
40
|
+
switchAccount(newAccount: Account): void;
|
|
41
|
+
switchPrivateKey(privateKey: Hex): void;
|
|
42
|
+
canSign(): boolean;
|
|
43
|
+
waitForTransaction(hash: string, confirmations?: number, timeout?: number): Promise<TransactionReceipt>;
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### Vault Types
|
|
48
|
+
|
|
49
|
+
Types for vault operations including deposits, withdrawals, and balance management:
|
|
50
|
+
|
|
51
|
+
```typescript
|
|
52
|
+
import { VaultAPI, Balance, TransactionResult } from "@0xmonaco/types";
|
|
53
|
+
|
|
54
|
+
// Vault operations
|
|
55
|
+
interface VaultAPI {
|
|
56
|
+
approve(token: string, amount: bigint): Promise<TransactionResult>;
|
|
57
|
+
deposit(token: string, amount: bigint): Promise<TransactionResult>;
|
|
58
|
+
withdraw(token: string, amount: bigint): Promise<TransactionResult>;
|
|
59
|
+
getBalance(token: string): Promise<Balance>;
|
|
60
|
+
getAllowance(token: string): Promise<bigint>;
|
|
61
|
+
needsApproval(token: string, amount: bigint): Promise<boolean>;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Vault response types
|
|
65
|
+
interface Balance {
|
|
66
|
+
token: string;
|
|
67
|
+
amount: bigint;
|
|
68
|
+
formatted: string;
|
|
69
|
+
symbol: string;
|
|
70
|
+
decimals: number;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
interface TransactionResult {
|
|
74
|
+
hash: string;
|
|
75
|
+
status: "pending" | "confirmed" | "failed";
|
|
76
|
+
nonce: bigint;
|
|
77
|
+
}
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### Trading Types
|
|
81
|
+
|
|
82
|
+
Types for trading operations including order placement and management:
|
|
83
|
+
|
|
84
|
+
```typescript
|
|
85
|
+
import {
|
|
86
|
+
TradingAPI,
|
|
87
|
+
OrderSide,
|
|
88
|
+
OrderType,
|
|
89
|
+
OrderIntent,
|
|
90
|
+
OrderResponse
|
|
91
|
+
} from "@0xmonaco/types";
|
|
92
|
+
|
|
93
|
+
// Trading operations
|
|
94
|
+
interface TradingAPI {
|
|
95
|
+
placeLimitOrder(market: string, side: OrderSide, size: bigint, price: bigint, options?: { timeInForce?: TimeInForce }): Promise<OrderResponse>;
|
|
96
|
+
placeMarketOrder(market: string, side: OrderSide, size: bigint, options?: { slippageToleranceBps?: number }): Promise<OrderResponse>;
|
|
97
|
+
placePostOnlyOrder(market: string, side: OrderSide, size: bigint, price: bigint): Promise<OrderResponse>;
|
|
98
|
+
replaceOrder(originalOrderId: string, newOrder: { market: string; side: OrderSide; size: bigint; price?: bigint; type: "limit" | "market" | "post_only"; timeInForce?: TimeInForce }): Promise<OrderResponse>;
|
|
99
|
+
cancelOrder(orderId: string): Promise<CancelOrderResponse>;
|
|
100
|
+
closePosition(market: string, options?: { maxSlippage?: number }): Promise<ClosePositionResponse>;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// Trading types
|
|
104
|
+
type OrderSide = "buy" | "sell";
|
|
105
|
+
|
|
106
|
+
type OrderType = "limit" | "market" | "post_only";
|
|
107
|
+
type TimeInForce = "GTC" | "IOC" | "FOK";
|
|
108
|
+
|
|
109
|
+
interface OrderIntent {
|
|
110
|
+
market: string;
|
|
111
|
+
side: OrderSide;
|
|
112
|
+
size: string;
|
|
113
|
+
orderType: OrderType;
|
|
114
|
+
userAddress: string;
|
|
115
|
+
timestamp: bigint;
|
|
116
|
+
nonce: bigint;
|
|
117
|
+
price?: string;
|
|
118
|
+
timeInForce?: TimeInForce;
|
|
119
|
+
slippageTolerance?: string;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// Trading response types
|
|
123
|
+
interface OrderResponse {
|
|
124
|
+
orderId: string;
|
|
125
|
+
status: "accepted" | "rejected";
|
|
126
|
+
timestamp: number;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
interface CancelOrderResponse {
|
|
130
|
+
orderId: string;
|
|
131
|
+
status: "cancelled" | "failed";
|
|
132
|
+
timestamp: number;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
interface ClosePositionResponse {
|
|
136
|
+
market: string;
|
|
137
|
+
status: "closed" | "no_position" | "partial_close";
|
|
138
|
+
closedSize?: bigint;
|
|
139
|
+
remainingSize?: bigint;
|
|
140
|
+
timestamp: number;
|
|
141
|
+
}
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### Contract Types
|
|
145
|
+
|
|
146
|
+
Types for contract addresses, instances, and contract-related operations:
|
|
147
|
+
|
|
148
|
+
```typescript
|
|
149
|
+
import { ContractAddresses, ContractInstances, Token, UserBalance } from "@0xmonaco/types";
|
|
150
|
+
|
|
151
|
+
// Contract addresses
|
|
152
|
+
interface ContractAddresses {
|
|
153
|
+
VAULT: string; // Vault contract address for managing user balances
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// Contract instances
|
|
157
|
+
type ContractInstances = {
|
|
158
|
+
vault: GetContractReturnType<typeof CONTRACT_ABIS.vault>;
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
// Contract-related types
|
|
162
|
+
interface Token {
|
|
163
|
+
address: string;
|
|
164
|
+
decimals: number;
|
|
165
|
+
symbol: string;
|
|
166
|
+
name: string;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
interface UserBalance {
|
|
170
|
+
token: Token;
|
|
171
|
+
amount: bigint;
|
|
172
|
+
formatted: string;
|
|
173
|
+
}
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
### Network Types
|
|
177
|
+
|
|
178
|
+
Types for network configuration:
|
|
179
|
+
|
|
180
|
+
```typescript
|
|
181
|
+
import { Network, NetworkEndpoints } from "@0xmonaco/types";
|
|
182
|
+
|
|
183
|
+
type Network = "mainnet" | "testnet";
|
|
184
|
+
|
|
185
|
+
interface NetworkEndpoints {
|
|
186
|
+
rpcUrl: string;
|
|
187
|
+
wsUrl?: string;
|
|
188
|
+
}
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
## Type Reference
|
|
192
|
+
|
|
193
|
+
### SDK Types
|
|
194
|
+
|
|
195
|
+
- `MonacoSDK`: Main SDK interface with vault and trading APIs
|
|
196
|
+
- `SDKConfig`: Configuration options for the Monaco SDK
|
|
197
|
+
- `Network`: Network type ("mainnet" | "testnet")
|
|
198
|
+
|
|
199
|
+
### Vault Types
|
|
200
|
+
|
|
201
|
+
- `VaultAPI`: Interface for vault operations (deposits, withdrawals, balances)
|
|
202
|
+
- `Balance`: Token balance information
|
|
203
|
+
- `TransactionResult`: Result of blockchain transactions
|
|
204
|
+
|
|
205
|
+
### Trading Types
|
|
206
|
+
|
|
207
|
+
- `TradingAPI`: Interface for trading operations (orders, positions)
|
|
208
|
+
- `OrderSide`: Order side type ("buy" | "sell")
|
|
209
|
+
- `OrderType`: Order type for different strategies
|
|
210
|
+
- `OrderIntent`: Intent interface for placing orders
|
|
211
|
+
- `OrderResponse`: Response from order operations
|
|
212
|
+
- `CancelOrderResponse`: Response from order cancellation
|
|
213
|
+
- `ClosePositionResponse`: Response from position closing
|
|
214
|
+
|
|
215
|
+
### Contract Types
|
|
216
|
+
|
|
217
|
+
- `ContractAddresses`: Contract address mappings
|
|
218
|
+
- `ContractInstances`: Typed contract instances
|
|
219
|
+
- `Token`: Token interface with metadata
|
|
220
|
+
- `UserBalance`: User's token balance information
|
|
221
|
+
|
|
222
|
+
## Project Structure
|
|
223
|
+
|
|
224
|
+
The types package is organized into domain-specific modules:
|
|
225
|
+
|
|
226
|
+
```
|
|
227
|
+
src/
|
|
228
|
+
├── sdk/ # SDK types
|
|
229
|
+
│ ├── index.ts # Main SDK interfaces and configuration
|
|
230
|
+
│ └── network.ts # Network-related types
|
|
231
|
+
├── vault/ # Vault types
|
|
232
|
+
│ ├── index.ts # Vault API interface
|
|
233
|
+
│ └── responses.ts # Vault response types
|
|
234
|
+
├── trading/ # Trading types
|
|
235
|
+
│ ├── index.ts # Trading API interface
|
|
236
|
+
│ ├── orders.ts # Order-related types
|
|
237
|
+
│ └── responses.ts # Trading response types
|
|
238
|
+
├── contracts/ # Contract types
|
|
239
|
+
│ ├── index.ts # Contract interfaces
|
|
240
|
+
│ └── balances.ts # Balance-related types
|
|
241
|
+
└── index.ts # Package exports
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
## Dependencies
|
|
245
|
+
|
|
246
|
+
This package uses `viem` for blockchain-related types:
|
|
247
|
+
|
|
248
|
+
- `Address`, `Hex`, `Account`, `WalletClient`, `PublicClient` from `viem`
|
|
249
|
+
- `GetContractReturnType` for contract instance typing
|
|
250
|
+
|
|
251
|
+
## Best Practices
|
|
252
|
+
|
|
253
|
+
- Keep types focused and single-purpose
|
|
254
|
+
- Use descriptive names that reflect the domain
|
|
255
|
+
- Document complex types with JSDoc comments
|
|
256
|
+
- Use TypeScript's strict mode
|
|
257
|
+
- Maintain backward compatibility
|
|
258
|
+
- Follow the established naming conventions
|
|
259
|
+
- Group related types in the same file
|
|
260
|
+
- Leverage `viem` types for blockchain operations rather than defining custom ones
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Auth Types
|
|
3
|
+
*
|
|
4
|
+
* Types for authentication operations including challenge creation,
|
|
5
|
+
* signature verification, and backend authentication.
|
|
6
|
+
*/
|
|
7
|
+
import { type ChallengeResponse, type VerifyResponse, type BackendAuthResponse, type TokenRefreshResponse, User } from "./responses";
|
|
8
|
+
/**
|
|
9
|
+
* Auth API interface.
|
|
10
|
+
* Provides methods for frontend and backend authentication.
|
|
11
|
+
* Handles challenge creation, signature verification, and backend auth.
|
|
12
|
+
*/
|
|
13
|
+
export interface AuthAPI {
|
|
14
|
+
/**
|
|
15
|
+
* Complete authentication flow for frontend applications.
|
|
16
|
+
*
|
|
17
|
+
* This method handles the entire authentication process:
|
|
18
|
+
* 1. Creates a challenge
|
|
19
|
+
* 2. Signs the challenge message
|
|
20
|
+
* 3. Verifies the signature and returns JWT tokens
|
|
21
|
+
*
|
|
22
|
+
* @param clientId - Client ID of the application
|
|
23
|
+
* @returns Promise resolving to the verification response with JWT tokens
|
|
24
|
+
*/
|
|
25
|
+
authenticate(clientId: string): Promise<VerifyResponse>;
|
|
26
|
+
/**
|
|
27
|
+
* Signs a challenge message using the wallet client.
|
|
28
|
+
*
|
|
29
|
+
* Signs the provided message using the wallet's private key.
|
|
30
|
+
* This is used in the authentication flow to prove ownership of the wallet.
|
|
31
|
+
*
|
|
32
|
+
* @param message - The message to sign
|
|
33
|
+
* @returns Promise resolving to the signature
|
|
34
|
+
*/
|
|
35
|
+
signChallenge(message: string): Promise<string>;
|
|
36
|
+
/**
|
|
37
|
+
* Creates a challenge for frontend authentication.
|
|
38
|
+
* Generates a unique nonce and message that the user must sign with their wallet.
|
|
39
|
+
* @param address - Wallet address of the user
|
|
40
|
+
* @param clientId - Client ID of the application
|
|
41
|
+
* @returns Promise resolving to the challenge response
|
|
42
|
+
*/
|
|
43
|
+
createChallenge(address: string, clientId: string): Promise<ChallengeResponse>;
|
|
44
|
+
/**
|
|
45
|
+
* Verifies a signature for frontend authentication.
|
|
46
|
+
* Validates the signature against the challenge and returns JWT tokens.
|
|
47
|
+
* @param address - Wallet address of the user
|
|
48
|
+
* @param signature - Signature of the challenge message
|
|
49
|
+
* @param nonce - Nonce from the challenge response
|
|
50
|
+
* @param clientId - Client ID of the application
|
|
51
|
+
* @returns Promise resolving to the verification response with JWT tokens
|
|
52
|
+
*/
|
|
53
|
+
verifySignature(address: string, signature: string, nonce: string, clientId: string): Promise<VerifyResponse>;
|
|
54
|
+
/**
|
|
55
|
+
* Authenticates a backend service using a secret key.
|
|
56
|
+
* Returns JWT tokens for API access.
|
|
57
|
+
* @param secretKey - Secret key of the application
|
|
58
|
+
* @returns Promise resolving to the backend auth response with JWT tokens
|
|
59
|
+
*/
|
|
60
|
+
authenticateBackend(secretKey: string): Promise<BackendAuthResponse>;
|
|
61
|
+
/**
|
|
62
|
+
* Refreshes an access token using a refresh token.
|
|
63
|
+
* @param refreshToken - The refresh token to use
|
|
64
|
+
* @returns Promise resolving to new access and refresh tokens
|
|
65
|
+
*/
|
|
66
|
+
refreshToken(refreshToken: string): Promise<TokenRefreshResponse>;
|
|
67
|
+
/**
|
|
68
|
+
* Revokes a refresh token.
|
|
69
|
+
* @param refreshToken - The refresh token to revoke
|
|
70
|
+
* @returns Promise resolving when the token is revoked
|
|
71
|
+
*/
|
|
72
|
+
revokeToken(refreshToken: string): Promise<void>;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Authentication state containing all tokens and metadata
|
|
76
|
+
*/
|
|
77
|
+
export interface AuthState {
|
|
78
|
+
/** JWT access token for authenticated requests */
|
|
79
|
+
accessToken: string;
|
|
80
|
+
/** JWT refresh token for token renewal */
|
|
81
|
+
refreshToken: string;
|
|
82
|
+
/** Unix timestamp when the access token expires */
|
|
83
|
+
expiresAt: number;
|
|
84
|
+
/** Information about the authenticated user */
|
|
85
|
+
user: User;
|
|
86
|
+
/** When the auth state was created */
|
|
87
|
+
createdAt: number;
|
|
88
|
+
}
|
|
89
|
+
export type { ChallengeResponse, VerifyResponse, BackendAuthResponse, TokenRefreshResponse, } from "./responses";
|
|
90
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/auth/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,KAAK,iBAAiB,EACtB,KAAK,cAAc,EACnB,KAAK,mBAAmB,EACxB,KAAK,oBAAoB,EACzB,IAAI,EACL,MAAM,aAAa,CAAC;AAMrB;;;;GAIG;AACH,MAAM,WAAW,OAAO;IACtB;;;;;;;;;;OAUG;IACH,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;IAExD;;;;;;;;OAQG;IACH,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAEhD;;;;;;OAMG;IACH,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;IAE/E;;;;;;;;OAQG;IACH,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;IAE9G;;;;;OAKG;IACH,mBAAmB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC;IAErE;;;;OAIG;IACH,YAAY,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC;IAElE;;;;OAIG;IACH,WAAW,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAClD;AAED;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,kDAAkD;IAClD,WAAW,EAAE,MAAM,CAAC;IACpB,0CAA0C;IAC1C,YAAY,EAAE,MAAM,CAAC;IACrB,mDAAmD;IACnD,SAAS,EAAE,MAAM,CAAC;IAClB,+CAA+C;IAC/C,IAAI,EAAE,IAAI,CAAC;IACX,sCAAsC;IACtC,SAAS,EAAE,MAAM,CAAC;CACnB;AAGD,YAAY,EACV,iBAAiB,EACjB,cAAc,EACd,mBAAmB,EACnB,oBAAoB,GACrB,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/auth/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Auth Response Types
|
|
3
|
+
*
|
|
4
|
+
* Response types for authentication operations.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Response to a challenge request.
|
|
8
|
+
*/
|
|
9
|
+
export interface ChallengeResponse {
|
|
10
|
+
/** Unique nonce for this challenge */
|
|
11
|
+
nonce: string;
|
|
12
|
+
/** Message to be signed by the user's wallet */
|
|
13
|
+
message: string;
|
|
14
|
+
/** Unix timestamp when the challenge expires */
|
|
15
|
+
expiresAt: number;
|
|
16
|
+
}
|
|
17
|
+
export interface User {
|
|
18
|
+
/** Unique identifier for the user */
|
|
19
|
+
id: string;
|
|
20
|
+
/** Wallet address of the user */
|
|
21
|
+
address: string;
|
|
22
|
+
/** Username of the user */
|
|
23
|
+
username?: string;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Response to a signature verification request.
|
|
27
|
+
*/
|
|
28
|
+
export interface VerifyResponse {
|
|
29
|
+
/** JWT access token for authenticated requests */
|
|
30
|
+
accessToken: string;
|
|
31
|
+
/** JWT refresh token for token renewal */
|
|
32
|
+
refreshToken: string;
|
|
33
|
+
/** Unix timestamp when the access token expires */
|
|
34
|
+
expiresAt: number;
|
|
35
|
+
/** Information about the authenticated user */
|
|
36
|
+
user: User;
|
|
37
|
+
}
|
|
38
|
+
export interface ApplicationInfo {
|
|
39
|
+
/** Unique identifier for the application */
|
|
40
|
+
id: string;
|
|
41
|
+
/** Human-readable name of the application */
|
|
42
|
+
name: string;
|
|
43
|
+
/** Client ID for frontend authentication */
|
|
44
|
+
clientId: string;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Response to a backend authentication request.
|
|
48
|
+
*/
|
|
49
|
+
export interface BackendAuthResponse {
|
|
50
|
+
/** JWT access token for authenticated requests */
|
|
51
|
+
accessToken: string;
|
|
52
|
+
/** Unix timestamp when the access token expires */
|
|
53
|
+
expiresAt: number;
|
|
54
|
+
/** Information about the application */
|
|
55
|
+
application: ApplicationInfo;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Response to a token refresh request.
|
|
59
|
+
*/
|
|
60
|
+
export interface TokenRefreshResponse {
|
|
61
|
+
/** New JWT access token */
|
|
62
|
+
accessToken: string;
|
|
63
|
+
/** Unix timestamp when the access token expires */
|
|
64
|
+
expiresAt: number;
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=responses.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"responses.d.ts","sourceRoot":"","sources":["../../src/auth/responses.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAMH;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,sCAAsC;IACtC,KAAK,EAAE,MAAM,CAAC;IACd,gDAAgD;IAChD,OAAO,EAAE,MAAM,CAAC;IAChB,gDAAgD;IAChD,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,IAAI;IACnB,qCAAqC;IACrC,EAAE,EAAE,MAAM,CAAC;IACX,iCAAiC;IACjC,OAAO,EAAE,MAAM,CAAC;IAChB,2BAA2B;IAC3B,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,kDAAkD;IAClD,WAAW,EAAE,MAAM,CAAC;IACpB,0CAA0C;IAC1C,YAAY,EAAE,MAAM,CAAC;IACrB,mDAAmD;IACnD,SAAS,EAAE,MAAM,CAAC;IAClB,+CAA+C;IAC/C,IAAI,EAAE,IAAI,CAAC;CACZ;AAED,MAAM,WAAW,eAAe;IAC9B,4CAA4C;IAC5C,EAAE,EAAE,MAAM,CAAC;IACX,6CAA6C;IAC7C,IAAI,EAAE,MAAM,CAAC;IACb,4CAA4C;IAC5C,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,kDAAkD;IAClD,WAAW,EAAE,MAAM,CAAC;IACpB,mDAAmD;IACnD,SAAS,EAAE,MAAM,CAAC;IAClB,wCAAwC;IACxC,WAAW,EAAE,eAAe,CAAC;CAC9B;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,2BAA2B;IAC3B,WAAW,EAAE,MAAM,CAAC;IACpB,mDAAmD;IACnD,SAAS,EAAE,MAAM,CAAC;CACnB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"responses.js","sourceRoot":"","sources":["../../src/auth/responses.ts"],"names":[],"mappings":"AAAA;;;;GAIG"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Contract Balance Types
|
|
3
|
+
*
|
|
4
|
+
* Types for contract balance management and token information.
|
|
5
|
+
*/
|
|
6
|
+
import { type Address } from "viem";
|
|
7
|
+
/**
|
|
8
|
+
* Type representing a token in the Monaco Markets protocol.
|
|
9
|
+
* Contains essential token metadata and contract information.
|
|
10
|
+
*
|
|
11
|
+
* @property address - Token contract address
|
|
12
|
+
* @property symbol - Token symbol (e.g. "ETH", "USDC")
|
|
13
|
+
* @property decimals - Number of decimal places for token amounts
|
|
14
|
+
* @property name - Full token name
|
|
15
|
+
*/
|
|
16
|
+
export interface Token {
|
|
17
|
+
/** Token contract address */
|
|
18
|
+
address: Address;
|
|
19
|
+
/** Token symbol (e.g. "ETH", "USDC") */
|
|
20
|
+
symbol: string;
|
|
21
|
+
/** Number of decimal places for token amounts */
|
|
22
|
+
decimals: number;
|
|
23
|
+
/** Full token name */
|
|
24
|
+
name: string;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Type representing a user's balance for a specific token in contract storage.
|
|
28
|
+
*
|
|
29
|
+
* @property token - Token address
|
|
30
|
+
* @property available - Available balance for trading
|
|
31
|
+
* @property locked - Locked balance in open orders
|
|
32
|
+
* @property total - Total balance (available + locked)
|
|
33
|
+
*/
|
|
34
|
+
export interface UserBalance {
|
|
35
|
+
/** Token address */
|
|
36
|
+
token: string;
|
|
37
|
+
/** Available balance for trading */
|
|
38
|
+
available: bigint;
|
|
39
|
+
/** Locked balance in open orders */
|
|
40
|
+
locked: bigint;
|
|
41
|
+
/** Total balance (available + locked) */
|
|
42
|
+
total: bigint;
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=balances.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"balances.d.ts","sourceRoot":"","sources":["../../src/contracts/balances.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,MAAM,CAAC;AAMpC;;;;;;;;GAQG;AACH,MAAM,WAAW,KAAK;IACpB,6BAA6B;IAC7B,OAAO,EAAE,OAAO,CAAC;IACjB,wCAAwC;IACxC,MAAM,EAAE,MAAM,CAAC;IACf,iDAAiD;IACjD,QAAQ,EAAE,MAAM,CAAC;IACjB,sBAAsB;IACtB,IAAI,EAAE,MAAM,CAAC;CACd;AAMD;;;;;;;GAOG;AACH,MAAM,WAAW,WAAW;IAC1B,oBAAoB;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,oCAAoC;IACpC,SAAS,EAAE,MAAM,CAAC;IAClB,oCAAoC;IACpC,MAAM,EAAE,MAAM,CAAC;IACf,yCAAyC;IACzC,KAAK,EAAE,MAAM,CAAC;CACf"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"balances.js","sourceRoot":"","sources":["../../src/contracts/balances.ts"],"names":[],"mappings":"AAAA;;;;GAIG"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Contract Types
|
|
3
|
+
*
|
|
4
|
+
* Types for contract addresses, instances, and contract-related operations.
|
|
5
|
+
*/
|
|
6
|
+
import { type GetContractReturnType } from "viem";
|
|
7
|
+
import { CONTRACT_ABIS } from "@0xmonaco/contracts";
|
|
8
|
+
/**
|
|
9
|
+
* Interface for all contract addresses in the Monaco Markets protocol.
|
|
10
|
+
*
|
|
11
|
+
* @property VAULT - Vault contract address for managing user balances
|
|
12
|
+
*/
|
|
13
|
+
export interface ContractAddresses {
|
|
14
|
+
/** Vault contract address for managing user balances */
|
|
15
|
+
VAULT: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Type representing all contract instances.
|
|
19
|
+
* Maps contract names to their typed instances with full ABI type safety.
|
|
20
|
+
*
|
|
21
|
+
* @property vault - Vault contract instance for managing user balances
|
|
22
|
+
*/
|
|
23
|
+
export type ContractInstances = {
|
|
24
|
+
/** Vault contract instance for managing user balances */
|
|
25
|
+
vault: GetContractReturnType<typeof CONTRACT_ABIS.vault>;
|
|
26
|
+
};
|
|
27
|
+
export type { Token, UserBalance } from "./balances";
|
|
28
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/contracts/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,KAAK,qBAAqB,EAAE,MAAM,MAAM,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAMpD;;;;GAIG;AACH,MAAM,WAAW,iBAAiB;IAChC,wDAAwD;IACxD,KAAK,EAAE,MAAM,CAAC;CACf;AAMD;;;;;GAKG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC9B,yDAAyD;IACzD,KAAK,EAAE,qBAAqB,CAAC,OAAO,aAAa,CAAC,KAAK,CAAC,CAAC;CAC1D,CAAC;AAGF,YAAY,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/contracts/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Monaco Types Package
|
|
3
|
+
*
|
|
4
|
+
* This package provides TypeScript types for the Monaco protocol.
|
|
5
|
+
* It includes SDK types, vault types, trading types, contract types, and common types.
|
|
6
|
+
*/
|
|
7
|
+
export * from "./sdk";
|
|
8
|
+
export * from "./vault";
|
|
9
|
+
export * from "./trading";
|
|
10
|
+
export * from "./contracts";
|
|
11
|
+
export * from "./auth";
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,cAAc,OAAO,CAAC;AACtB,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,QAAQ,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Monaco Types Package
|
|
3
|
+
*
|
|
4
|
+
* This package provides TypeScript types for the Monaco protocol.
|
|
5
|
+
* It includes SDK types, vault types, trading types, contract types, and common types.
|
|
6
|
+
*/
|
|
7
|
+
// Export everything from all modules
|
|
8
|
+
export * from "./sdk";
|
|
9
|
+
export * from "./vault";
|
|
10
|
+
export * from "./trading";
|
|
11
|
+
export * from "./contracts";
|
|
12
|
+
export * from "./auth";
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,qCAAqC;AACrC,cAAc,OAAO,CAAC;AACtB,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,QAAQ,CAAC"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SDK Types
|
|
3
|
+
*
|
|
4
|
+
* Core SDK configuration and main interface types.
|
|
5
|
+
*/
|
|
6
|
+
import { type PrivateKeyAccount, type Account, type WalletClient, type TransactionReceipt, type PublicClient, type Hex } from "viem";
|
|
7
|
+
import { type Network } from "./network";
|
|
8
|
+
import { type VaultAPI } from "../vault";
|
|
9
|
+
import { type TradingAPI } from "../trading";
|
|
10
|
+
import { AuthState, type AuthAPI } from "../auth";
|
|
11
|
+
/**
|
|
12
|
+
* Configuration options for the Monaco SDK.
|
|
13
|
+
*
|
|
14
|
+
* The SDK supports multiple authentication methods:
|
|
15
|
+
* - `privateKey`: Hex string (0x-prefixed) for direct private key usage
|
|
16
|
+
* - `signer`: Viem PrivateKeyAccount for more control over account management
|
|
17
|
+
* - `account`: Custom Account implementation (overrides privateKey/signer)
|
|
18
|
+
*
|
|
19
|
+
* At least one authentication method must be provided.
|
|
20
|
+
*
|
|
21
|
+
* The SDK supports Sei Mainnet and Sei Testnet, defaulting to mainnet if no network is specified.
|
|
22
|
+
*/
|
|
23
|
+
export interface SDKConfig {
|
|
24
|
+
/** Private key as hex string (0x-prefixed) */
|
|
25
|
+
privateKey?: Hex;
|
|
26
|
+
/** Viem Account for advanced account management */
|
|
27
|
+
signer?: PrivateKeyAccount;
|
|
28
|
+
/** Custom Account implementation (overrides privateKey/signer) */
|
|
29
|
+
account?: Account;
|
|
30
|
+
/** Optional network override (defaults to 'mainnet') */
|
|
31
|
+
network?: Network;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Core SDK interface providing access to all Monaco functionality.
|
|
35
|
+
*/
|
|
36
|
+
export interface MonacoSDK {
|
|
37
|
+
/** Auth operations API */
|
|
38
|
+
auth: AuthAPI;
|
|
39
|
+
/** Vault operations API */
|
|
40
|
+
vault: VaultAPI;
|
|
41
|
+
/** Trading operations API */
|
|
42
|
+
trading: TradingAPI;
|
|
43
|
+
/** Wallet client for all blockchain operations */
|
|
44
|
+
walletClient: WalletClient;
|
|
45
|
+
/** Public client for read-only blockchain operations */
|
|
46
|
+
publicClient: PublicClient;
|
|
47
|
+
/** Complete authentication flow */
|
|
48
|
+
login(clientId: string): Promise<AuthState>;
|
|
49
|
+
/** Get the current authentication state */
|
|
50
|
+
getAuthState(): AuthState | undefined;
|
|
51
|
+
/** Check if the user is authenticated */
|
|
52
|
+
isAuthenticated(): boolean;
|
|
53
|
+
/** Check connection status */
|
|
54
|
+
isConnected(): boolean;
|
|
55
|
+
/** Get the current account address */
|
|
56
|
+
getAccountAddress(): string;
|
|
57
|
+
/** Get the current network ('mainnet' or 'testnet') */
|
|
58
|
+
getNetwork(): Network;
|
|
59
|
+
/** Get the current chain ID */
|
|
60
|
+
getChainId(): number;
|
|
61
|
+
/** Switch to a different account */
|
|
62
|
+
switchAccount(newAccount: Account): void;
|
|
63
|
+
/** Switch to a different private key */
|
|
64
|
+
switchPrivateKey(privateKey: Hex): void;
|
|
65
|
+
/** Check if the current account can sign messages */
|
|
66
|
+
canSign(): boolean;
|
|
67
|
+
/** Wait for a transaction to be confirmed */
|
|
68
|
+
waitForTransaction(hash: string, confirmations?: number, timeout?: number): Promise<TransactionReceipt>;
|
|
69
|
+
}
|
|
70
|
+
export type { Network, NetworkEndpoints } from "./network";
|
|
71
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/sdk/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACL,KAAK,iBAAiB,EACtB,KAAK,OAAO,EACZ,KAAK,YAAY,EACjB,KAAK,kBAAkB,EACvB,KAAK,YAAY,EACjB,KAAK,GAAG,EACT,MAAM,MAAM,CAAC;AACd,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAkB,KAAK,OAAO,EAAE,MAAM,SAAS,CAAC;AAMlE;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,SAAS;IACxB,8CAA8C;IAC9C,UAAU,CAAC,EAAE,GAAG,CAAC;IAEjB,mDAAmD;IACnD,MAAM,CAAC,EAAE,iBAAiB,CAAC;IAE3B,kEAAkE;IAClE,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB,wDAAwD;IACxD,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAMD;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,0BAA0B;IAC1B,IAAI,EAAE,OAAO,CAAC;IAEd,2BAA2B;IAC3B,KAAK,EAAE,QAAQ,CAAC;IAEhB,6BAA6B;IAC7B,OAAO,EAAE,UAAU,CAAC;IAEpB,kDAAkD;IAClD,YAAY,EAAE,YAAY,CAAC;IAE3B,wDAAwD;IACxD,YAAY,EAAE,YAAY,CAAC;IAE3B,mCAAmC;IACnC,KAAK,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;IAE5C,2CAA2C;IAC3C,YAAY,IAAI,SAAS,GAAG,SAAS,CAAC;IAEtC,yCAAyC;IACzC,eAAe,IAAI,OAAO,CAAC;IAE3B,8BAA8B;IAC9B,WAAW,IAAI,OAAO,CAAC;IAEvB,sCAAsC;IACtC,iBAAiB,IAAI,MAAM,CAAC;IAE5B,uDAAuD;IACvD,UAAU,IAAI,OAAO,CAAC;IAEtB,+BAA+B;IAC/B,UAAU,IAAI,MAAM,CAAC;IAErB,oCAAoC;IACpC,aAAa,CAAC,UAAU,EAAE,OAAO,GAAG,IAAI,CAAC;IAEzC,wCAAwC;IACxC,gBAAgB,CAAC,UAAU,EAAE,GAAG,GAAG,IAAI,CAAC;IAExC,qDAAqD;IACrD,OAAO,IAAI,OAAO,CAAC;IAEnB,6CAA6C;IAC7C,kBAAkB,CAChB,IAAI,EAAE,MAAM,EACZ,aAAa,CAAC,EAAE,MAAM,EACtB,OAAO,CAAC,EAAE,MAAM,GACf,OAAO,CAAC,kBAAkB,CAAC,CAAC;CAChC;AAGD,YAAY,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/sdk/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Network Types
|
|
3
|
+
*
|
|
4
|
+
* Network configuration and endpoint types for the Monaco SDK.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Supported network types for the Monaco SDK.
|
|
8
|
+
*
|
|
9
|
+
* The SDK supports Sei Mainnet and Sei Testnet networks.
|
|
10
|
+
*/
|
|
11
|
+
export type Network = "mainnet" | "testnet";
|
|
12
|
+
/**
|
|
13
|
+
* Network endpoint configuration for the Monaco SDK.
|
|
14
|
+
*
|
|
15
|
+
* Contains the RPC URL and API URL for each supported network.
|
|
16
|
+
*/
|
|
17
|
+
export interface NetworkEndpoints {
|
|
18
|
+
rpcUrl: string;
|
|
19
|
+
apiUrl: string;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=network.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"network.d.ts","sourceRoot":"","sources":["../../src/sdk/network.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAMH;;;;GAIG;AACH,MAAM,MAAM,OAAO,GAAG,SAAS,GAAG,SAAS,CAAC;AAE5C;;;;GAIG;AACH,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;CAChB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"network.js","sourceRoot":"","sources":["../../src/sdk/network.ts"],"names":[],"mappings":"AAAA;;;;GAIG"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Trading Types
|
|
3
|
+
*
|
|
4
|
+
* Types for trading operations including order placement and management.
|
|
5
|
+
*/
|
|
6
|
+
import { type OrderSide } from "./orders";
|
|
7
|
+
import { type CancelOrderResponse, type UpdateOrderResponse, type CreateOrderResponse } from "./responses";
|
|
8
|
+
/**
|
|
9
|
+
* Trading API interface.
|
|
10
|
+
* Provides methods for placing and managing orders.
|
|
11
|
+
* Handles order placement, cancellation, and execution.
|
|
12
|
+
*/
|
|
13
|
+
export interface TradingAPI {
|
|
14
|
+
/**
|
|
15
|
+
* Set the access token for the TradingAPI
|
|
16
|
+
* @param token - The access token to set
|
|
17
|
+
*/
|
|
18
|
+
setAccessToken(token: string): void;
|
|
19
|
+
/**
|
|
20
|
+
* Places a limit order on the order book.
|
|
21
|
+
* @param market - Market identifier (e.g., "ETH-USD")
|
|
22
|
+
* @param side - Order side ("BUY" or "SELL")
|
|
23
|
+
* @param quantity - Order quantity as string
|
|
24
|
+
* @param price - Order price as string
|
|
25
|
+
* @param options - Optional parameters for the limit order
|
|
26
|
+
* @param options.tradingMode - Trading mode (e.g., "SPOT")
|
|
27
|
+
* @returns Promise resolving to the order result
|
|
28
|
+
*/
|
|
29
|
+
placeLimitOrder(market: string, side: OrderSide, quantity: string, price: string, options?: {
|
|
30
|
+
tradingMode?: string;
|
|
31
|
+
}): Promise<CreateOrderResponse>;
|
|
32
|
+
/**
|
|
33
|
+
* Places a market order for immediate execution.
|
|
34
|
+
* @param market - Market identifier (e.g., "ETH-USD")
|
|
35
|
+
* @param side - Order side ("BUY" or "SELL")
|
|
36
|
+
* @param quantity - Order quantity as string
|
|
37
|
+
* @param options - Optional parameters for the market order
|
|
38
|
+
* @param options.tradingMode - Trading mode (e.g., "SPOT")
|
|
39
|
+
* @returns Promise resolving to the order result
|
|
40
|
+
*/
|
|
41
|
+
placeMarketOrder(market: string, side: OrderSide, quantity: string, options?: {
|
|
42
|
+
tradingMode?: string;
|
|
43
|
+
}): Promise<CreateOrderResponse>;
|
|
44
|
+
/**
|
|
45
|
+
* Cancels an existing order.
|
|
46
|
+
* @param orderId - ID of the order to cancel
|
|
47
|
+
* @returns Promise resolving to the cancellation result
|
|
48
|
+
*/
|
|
49
|
+
cancelOrder(orderId: string): Promise<CancelOrderResponse>;
|
|
50
|
+
/**
|
|
51
|
+
* Updates an existing order (price and/or quantity).
|
|
52
|
+
* @param orderId - ID of the order to update
|
|
53
|
+
* @param updates - Fields to update
|
|
54
|
+
* @param updates.price - New price (optional)
|
|
55
|
+
* @param updates.quantity - New quantity (optional)
|
|
56
|
+
* @returns Promise resolving to the update result
|
|
57
|
+
*/
|
|
58
|
+
updateOrder(orderId: string, updates: {
|
|
59
|
+
price?: string;
|
|
60
|
+
quantity?: string;
|
|
61
|
+
}): Promise<UpdateOrderResponse>;
|
|
62
|
+
}
|
|
63
|
+
export type { OrderSide, OrderType, } from "./orders";
|
|
64
|
+
export type { OrderResponse, CancelOrderResponse, UpdateOrderResponse, CreateOrderResponse } from "./responses";
|
|
65
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/trading/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,UAAU,CAAC;AAC1C,OAAO,EACL,KAAK,mBAAmB,EACxB,KAAK,mBAAmB,EACxB,KAAK,mBAAmB,EACzB,MAAM,aAAa,CAAC;AAMrB;;;;GAIG;AACH,MAAM,WAAW,UAAU;IACzB;;;OAGG;IACH,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAEpC;;;;;;;;;OASG;IACH,eAAe,CACb,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,SAAS,EACf,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,MAAM,EACb,OAAO,CAAC,EAAE;QACR,WAAW,CAAC,EAAE,MAAM,CAAC;KACtB,GACA,OAAO,CAAC,mBAAmB,CAAC,CAAC;IAEhC;;;;;;;;OAQG;IACH,gBAAgB,CACd,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,SAAS,EACf,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE;QACR,WAAW,CAAC,EAAE,MAAM,CAAC;KACtB,GACA,OAAO,CAAC,mBAAmB,CAAC,CAAC;IAEhC;;;;OAIG;IACH,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC;IAE3D;;;;;;;OAOG;IACH,WAAW,CACT,OAAO,EAAE,MAAM,EACf,OAAO,EAAE;QACP,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,QAAQ,CAAC,EAAE,MAAM,CAAC;KACnB,GACA,OAAO,CAAC,mBAAmB,CAAC,CAAC;CACjC;AAGD,YAAY,EACV,SAAS,EACT,SAAS,GACV,MAAM,UAAU,CAAC;AAElB,YAAY,EACV,aAAa,EACb,mBAAmB,EACnB,mBAAmB,EACnB,mBAAmB,EACpB,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/trading/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Trading Order Types
|
|
3
|
+
*
|
|
4
|
+
* Types for trading operations and order management.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Order side for trading operations
|
|
8
|
+
*/
|
|
9
|
+
export type OrderSide = "BUY" | "SELL";
|
|
10
|
+
/**
|
|
11
|
+
* Order type for different order strategies
|
|
12
|
+
*/
|
|
13
|
+
export type OrderType = "LIMIT" | "MARKET" | "POST_ONLY";
|
|
14
|
+
/**
|
|
15
|
+
* Order status for different order states
|
|
16
|
+
*/
|
|
17
|
+
export type OrderStatus = "SUBMITTED" | "FILLED" | "CANCELLED" | "REJECTED" | "PARTIALLY_FILLED";
|
|
18
|
+
/**
|
|
19
|
+
* Trading mode
|
|
20
|
+
*/
|
|
21
|
+
export type TradingMode = "SPOT" | "MARGIN" | "FUTURES";
|
|
22
|
+
//# sourceMappingURL=orders.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"orders.d.ts","sourceRoot":"","sources":["../../src/trading/orders.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAMH;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG,KAAK,GAAG,MAAM,CAAC;AAEvC;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG,OAAO,GAAG,QAAQ,GAAG,WAAW,CAAC;AAEzD;;GAEG;AACH,MAAM,MAAM,WAAW,GACnB,WAAW,GACX,QAAQ,GACR,WAAW,GACX,UAAU,GACV,kBAAkB,CAAC;AAEvB;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,QAAQ,GAAG,SAAS,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"orders.js","sourceRoot":"","sources":["../../src/trading/orders.ts"],"names":[],"mappings":"AAAA;;;;GAIG"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Trading Response Types
|
|
3
|
+
*
|
|
4
|
+
* Response types for trading operations.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Response from creating an order.
|
|
8
|
+
*/
|
|
9
|
+
export interface CreateOrderResponse {
|
|
10
|
+
/** Order identifier */
|
|
11
|
+
order_id: string;
|
|
12
|
+
/** Order status */
|
|
13
|
+
status: "SUCCESS" | "FAILED";
|
|
14
|
+
/** Match result information */
|
|
15
|
+
match_result?: {
|
|
16
|
+
/** Remaining quantity after immediate matches */
|
|
17
|
+
remaining_quantity: string;
|
|
18
|
+
/** Status of the match */
|
|
19
|
+
status: string;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Response from cancelling an order.
|
|
24
|
+
*/
|
|
25
|
+
export interface CancelOrderResponse {
|
|
26
|
+
/** Order identifier */
|
|
27
|
+
order_id: string;
|
|
28
|
+
/** Cancellation status */
|
|
29
|
+
status: "SUCCESS" | "FAILED";
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Response from updating an order.
|
|
33
|
+
*/
|
|
34
|
+
export interface UpdateOrderResponse {
|
|
35
|
+
/** Order identifier */
|
|
36
|
+
order_id: string;
|
|
37
|
+
/** Update status */
|
|
38
|
+
status: "SUCCESS" | "FAILED";
|
|
39
|
+
/** Updated fields */
|
|
40
|
+
updated_fields: {
|
|
41
|
+
/** Updated price if changed */
|
|
42
|
+
price?: string;
|
|
43
|
+
/** Updated quantity if changed */
|
|
44
|
+
quantity?: string;
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Response from placing an order (legacy - kept for backward compatibility).
|
|
49
|
+
*/
|
|
50
|
+
export interface OrderResponse {
|
|
51
|
+
/** Order identifier */
|
|
52
|
+
orderId: string;
|
|
53
|
+
/** Order status */
|
|
54
|
+
status: "accepted" | "rejected";
|
|
55
|
+
/** Timestamp of the response */
|
|
56
|
+
timestamp: number;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Response from closing a position (legacy - kept for backward compatibility).
|
|
60
|
+
*/
|
|
61
|
+
export interface ClosePositionResponse {
|
|
62
|
+
/** Market identifier */
|
|
63
|
+
market: string;
|
|
64
|
+
/** Close position status */
|
|
65
|
+
status: "closed" | "no_position" | "partial_close";
|
|
66
|
+
/** Amount that was closed */
|
|
67
|
+
closedSize?: bigint;
|
|
68
|
+
/** Remaining position size */
|
|
69
|
+
remainingSize?: bigint;
|
|
70
|
+
/** Timestamp of the response */
|
|
71
|
+
timestamp: number;
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=responses.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"responses.d.ts","sourceRoot":"","sources":["../../src/trading/responses.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAQH;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,uBAAuB;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,mBAAmB;IACnB,MAAM,EAAE,SAAS,GAAG,QAAQ,CAAC;IAC7B,+BAA+B;IAC/B,YAAY,CAAC,EAAE;QACb,iDAAiD;QACjD,kBAAkB,EAAE,MAAM,CAAC;QAC3B,0BAA0B;QAC1B,MAAM,EAAE,MAAM,CAAC;KAChB,CAAC;CACH;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,uBAAuB;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,0BAA0B;IAC1B,MAAM,EAAE,SAAS,GAAG,QAAQ,CAAC;CAC9B;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,uBAAuB;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,oBAAoB;IACpB,MAAM,EAAE,SAAS,GAAG,QAAQ,CAAC;IAC7B,qBAAqB;IACrB,cAAc,EAAE;QACd,+BAA+B;QAC/B,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,kCAAkC;QAClC,QAAQ,CAAC,EAAE,MAAM,CAAC;KACnB,CAAC;CACH;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,uBAAuB;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,mBAAmB;IACnB,MAAM,EAAE,UAAU,GAAG,UAAU,CAAC;IAChC,gCAAgC;IAChC,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,wBAAwB;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,4BAA4B;IAC5B,MAAM,EAAE,QAAQ,GAAG,aAAa,GAAG,eAAe,CAAC;IACnD,6BAA6B;IAC7B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,8BAA8B;IAC9B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,gCAAgC;IAChC,SAAS,EAAE,MAAM,CAAC;CACnB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"responses.js","sourceRoot":"","sources":["../../src/trading/responses.ts"],"names":[],"mappings":"AAAA;;;;GAIG"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vault Types
|
|
3
|
+
*
|
|
4
|
+
* Types for vault operations including deposits, withdrawals, and balance management.
|
|
5
|
+
*/
|
|
6
|
+
import { type Balance, type TransactionResult } from "./responses";
|
|
7
|
+
/**
|
|
8
|
+
* Vault API interface.
|
|
9
|
+
* Provides methods for managing token deposits and withdrawals.
|
|
10
|
+
* Handles token approvals and balance management.
|
|
11
|
+
*/
|
|
12
|
+
export interface VaultAPI {
|
|
13
|
+
/**
|
|
14
|
+
* Approves the vault to spend tokens.
|
|
15
|
+
* @param token - Address of the token to approve
|
|
16
|
+
* @param amount - Amount to approve
|
|
17
|
+
* @returns Promise resolving to the transaction result
|
|
18
|
+
*/
|
|
19
|
+
approve(token: string, amount: bigint): Promise<TransactionResult>;
|
|
20
|
+
/**
|
|
21
|
+
* Deposits tokens into the vault.
|
|
22
|
+
* @param token - Address of the token to deposit
|
|
23
|
+
* @param amount - Amount to deposit
|
|
24
|
+
* @returns Promise resolving to the transaction result
|
|
25
|
+
*/
|
|
26
|
+
deposit(token: string, amount: bigint): Promise<TransactionResult>;
|
|
27
|
+
/**
|
|
28
|
+
* Withdraws tokens from the vault.
|
|
29
|
+
* @param token - Address of the token to withdraw
|
|
30
|
+
* @param amount - Amount to withdraw
|
|
31
|
+
* @returns Promise resolving to the transaction result
|
|
32
|
+
*/
|
|
33
|
+
withdraw(token: string, amount: bigint): Promise<TransactionResult>;
|
|
34
|
+
/**
|
|
35
|
+
* Gets the balance of a token in the vault.
|
|
36
|
+
* @param token - Address of the token to check
|
|
37
|
+
* @returns Promise resolving to the balance
|
|
38
|
+
*/
|
|
39
|
+
getBalance(token: string): Promise<Balance>;
|
|
40
|
+
/**
|
|
41
|
+
* Gets the allowance for a token.
|
|
42
|
+
* @param token - Address of the token to check
|
|
43
|
+
* @returns Promise resolving to the allowance
|
|
44
|
+
*/
|
|
45
|
+
getAllowance(token: string): Promise<bigint>;
|
|
46
|
+
/**
|
|
47
|
+
* Checks if a token needs approval for an amount.
|
|
48
|
+
* @param token - Address of the token to check
|
|
49
|
+
* @param amount - Amount to check
|
|
50
|
+
* @returns Promise resolving to whether approval is needed
|
|
51
|
+
*/
|
|
52
|
+
needsApproval(token: string, amount: bigint): Promise<boolean>;
|
|
53
|
+
/**
|
|
54
|
+
* Set the access token for the VaultAPI
|
|
55
|
+
* @param token - The access token to set
|
|
56
|
+
*/
|
|
57
|
+
setAccessToken(token: string): void;
|
|
58
|
+
}
|
|
59
|
+
export type { Balance, TransactionResult } from "./responses";
|
|
60
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/vault/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,KAAK,OAAO,EAAE,KAAK,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAMnE;;;;GAIG;AACH,MAAM,WAAW,QAAQ;IACvB;;;;;OAKG;IACH,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;IAEnE;;;;;OAKG;IACH,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;IAEnE;;;;;OAKG;IACH,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;IAEpE;;;;OAIG;IACH,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAE5C;;;;OAIG;IACH,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAE7C;;;;;OAKG;IACH,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAE/D;;;OAGG;IACH,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;CACrC;AAGD,YAAY,EAAE,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/vault/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vault Response Types
|
|
3
|
+
*
|
|
4
|
+
* Response types for vault operations.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Response from a transaction.
|
|
8
|
+
*/
|
|
9
|
+
export interface TransactionResult {
|
|
10
|
+
/** Transaction hash */
|
|
11
|
+
hash: string;
|
|
12
|
+
/** Transaction status */
|
|
13
|
+
status: "pending" | "confirmed" | "failed";
|
|
14
|
+
/** Nonce used for this operation */
|
|
15
|
+
nonce: bigint;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Token balance information.
|
|
19
|
+
*/
|
|
20
|
+
export interface Balance {
|
|
21
|
+
/** Token address */
|
|
22
|
+
token: string;
|
|
23
|
+
/** Balance amount */
|
|
24
|
+
amount: bigint;
|
|
25
|
+
/** Formatted balance string */
|
|
26
|
+
formatted: string;
|
|
27
|
+
/** Token symbol */
|
|
28
|
+
symbol: string;
|
|
29
|
+
/** Token decimals */
|
|
30
|
+
decimals: number;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=responses.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"responses.d.ts","sourceRoot":"","sources":["../../src/vault/responses.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAMH;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,uBAAuB;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,yBAAyB;IACzB,MAAM,EAAE,SAAS,GAAG,WAAW,GAAG,QAAQ,CAAC;IAC3C,oCAAoC;IACpC,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;GAEG;AACH,MAAM,WAAW,OAAO;IACtB,oBAAoB;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,qBAAqB;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,+BAA+B;IAC/B,SAAS,EAAE,MAAM,CAAC;IAClB,mBAAmB;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,qBAAqB;IACrB,QAAQ,EAAE,MAAM,CAAC;CAClB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"responses.js","sourceRoot":"","sources":["../../src/vault/responses.ts"],"names":[],"mappings":"AAAA;;;;GAIG"}
|
package/package.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@0xmonaco/types",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"viem": "^2.30.6"
|
|
13
|
+
},
|
|
14
|
+
"devDependencies": {
|
|
15
|
+
"typescript": "5.7.3"
|
|
16
|
+
},
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"default": "./dist/index.js"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"scripts": {
|
|
24
|
+
"build": "tsc -b",
|
|
25
|
+
"dev": "tsc --watch",
|
|
26
|
+
"clean": "rm -rf dist",
|
|
27
|
+
"lint": "eslint src --ext .ts"
|
|
28
|
+
}
|
|
29
|
+
}
|