lynx-client 0.0.1-beta.11 → 0.0.1-beta.13
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 +370 -3
- package/dist/cjs/index.js +2 -0
- package/dist/cjs/lib/chains/chainMappings.js +17 -0
- package/dist/cjs/lib/contractsIntegration/OrderBookService/OrderBookService.js +52 -7
- package/dist/cjs/lib/devex/getChainAddresses.js +65 -0
- package/dist/cjs/lib/devex/getSupportedEngineChains.js +45 -0
- package/dist/cjs/lib/devex/index.js +9 -0
- package/dist/cjs/lib/devex/types.js +2 -0
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +2 -0
- package/dist/esm/lib/chains/chainMappings.d.ts +13 -0
- package/dist/esm/lib/chains/chainMappings.d.ts.map +1 -0
- package/dist/esm/lib/chains/chainMappings.js +17 -0
- package/dist/esm/lib/chains/chainTypes.d.ts +3 -0
- package/dist/esm/lib/chains/chainTypes.d.ts.map +1 -1
- package/dist/esm/lib/contractsIntegration/OrderBookService/IOrderBookService.d.ts +27 -1
- package/dist/esm/lib/contractsIntegration/OrderBookService/IOrderBookService.d.ts.map +1 -1
- package/dist/esm/lib/contractsIntegration/OrderBookService/OrderBookService.d.ts +5 -12
- package/dist/esm/lib/contractsIntegration/OrderBookService/OrderBookService.d.ts.map +1 -1
- package/dist/esm/lib/contractsIntegration/OrderBookService/OrderBookService.js +52 -7
- package/dist/esm/lib/devex/getChainAddresses.d.ts +20 -0
- package/dist/esm/lib/devex/getChainAddresses.d.ts.map +1 -0
- package/dist/esm/lib/devex/getChainAddresses.js +65 -0
- package/dist/esm/lib/devex/getSupportedEngineChains.d.ts +37 -0
- package/dist/esm/lib/devex/getSupportedEngineChains.d.ts.map +1 -0
- package/dist/esm/lib/devex/getSupportedEngineChains.js +45 -0
- package/dist/esm/lib/devex/index.d.ts +5 -0
- package/dist/esm/lib/devex/index.d.ts.map +1 -0
- package/dist/esm/lib/devex/index.js +9 -0
- package/dist/esm/lib/devex/types.d.ts +20 -0
- package/dist/esm/lib/devex/types.d.ts.map +1 -0
- package/dist/esm/lib/devex/types.js +2 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/lib/chains/chainMappings.d.ts +13 -0
- package/dist/types/lib/chains/chainMappings.d.ts.map +1 -0
- package/dist/types/lib/chains/chainTypes.d.ts +3 -0
- package/dist/types/lib/chains/chainTypes.d.ts.map +1 -1
- package/dist/types/lib/contractsIntegration/OrderBookService/IOrderBookService.d.ts +27 -1
- package/dist/types/lib/contractsIntegration/OrderBookService/IOrderBookService.d.ts.map +1 -1
- package/dist/types/lib/contractsIntegration/OrderBookService/OrderBookService.d.ts +5 -12
- package/dist/types/lib/contractsIntegration/OrderBookService/OrderBookService.d.ts.map +1 -1
- package/dist/types/lib/devex/getChainAddresses.d.ts +20 -0
- package/dist/types/lib/devex/getChainAddresses.d.ts.map +1 -0
- package/dist/types/lib/devex/getSupportedEngineChains.d.ts +37 -0
- package/dist/types/lib/devex/getSupportedEngineChains.d.ts.map +1 -0
- package/dist/types/lib/devex/index.d.ts +5 -0
- package/dist/types/lib/devex/index.d.ts.map +1 -0
- package/dist/types/lib/devex/types.d.ts +20 -0
- package/dist/types/lib/devex/types.d.ts.map +1 -0
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -1,4 +1,371 @@
|
|
|
1
|
-
# Lynx Client
|
|
1
|
+
# Lynx Client SDK
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
A TypeScript SDK for interacting with the Lynx trading protocol across multiple EVM-compatible blockchains.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- 🔒 Type-safe interfaces for all Lynx smart contracts
|
|
8
|
+
- 🌐 Multi-chain support (16+ EVM chains)
|
|
9
|
+
- 📊 Built-in utilities for price, leverage, and fraction conversions
|
|
10
|
+
- 🏗️ Support for both CommonJS and ESM module systems
|
|
11
|
+
- 🔍 Read-only lens contracts for efficient data aggregation
|
|
12
|
+
- 💼 Complete trading lifecycle management
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install lynx-client
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
yarn add lynx-client
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Quick Start
|
|
25
|
+
|
|
26
|
+
```typescript
|
|
27
|
+
import {
|
|
28
|
+
connectToLatestRegistry,
|
|
29
|
+
LynxSystemAddresses,
|
|
30
|
+
createTradersPortalService,
|
|
31
|
+
buildPositionRequestIdentifier,
|
|
32
|
+
buildPositionRequestParams
|
|
33
|
+
} from 'lynx-client';
|
|
34
|
+
import { ethers } from 'ethers';
|
|
35
|
+
|
|
36
|
+
// Initialize provider
|
|
37
|
+
const provider = new ethers.JsonRpcProvider('YOUR_RPC_URL');
|
|
38
|
+
const signer = await provider.getSigner();
|
|
39
|
+
|
|
40
|
+
// Get chain-specific addresses
|
|
41
|
+
const addresses = LynxSystemAddresses.arbitrum; // or .sonic, .base, etc.
|
|
42
|
+
|
|
43
|
+
// Connect to contracts
|
|
44
|
+
const registry = connectToLatestRegistry(provider, addresses.registryProxyAddress);
|
|
45
|
+
|
|
46
|
+
// Create a service for trader operations
|
|
47
|
+
const tradersPortal = createTradersPortalService(signer, addresses.tradersPortalAddress);
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Core Concepts
|
|
51
|
+
|
|
52
|
+
### Supported Chains
|
|
53
|
+
|
|
54
|
+
#### Engine Chains
|
|
55
|
+
The Lynx protocol is deployed on the following chains:
|
|
56
|
+
|
|
57
|
+
- **Sonic** (146)
|
|
58
|
+
- **Boba** (288)
|
|
59
|
+
- **Flare** (14)
|
|
60
|
+
- **Fantom** (250)
|
|
61
|
+
|
|
62
|
+
#### Source Chains
|
|
63
|
+
Assets can be bridged from these additional chains:
|
|
64
|
+
|
|
65
|
+
- Ethereum Mainnet (1)
|
|
66
|
+
- Optimism (10)
|
|
67
|
+
- BSC (56)
|
|
68
|
+
- Polygon (137)
|
|
69
|
+
- Fuse (122)
|
|
70
|
+
- Goat (2345)
|
|
71
|
+
- Mantle (5000)
|
|
72
|
+
- Base (8453)
|
|
73
|
+
- Mode (34443)
|
|
74
|
+
- Arbitrum (42161)
|
|
75
|
+
- Celo (42220)
|
|
76
|
+
- Linea (59144)
|
|
77
|
+
- Zircuit (48900)
|
|
78
|
+
|
|
79
|
+
```typescript
|
|
80
|
+
import { LynxSystemAddresses, TSupportedChainIds } from 'lynx-client';
|
|
81
|
+
|
|
82
|
+
// Get addresses for a specific chain
|
|
83
|
+
const sonicAddresses = LynxSystemAddresses.sonic;
|
|
84
|
+
const arbitrumAddresses = LynxSystemAddresses.arbitrum;
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### Contract Services
|
|
88
|
+
|
|
89
|
+
The SDK provides service wrappers for all Lynx contracts:
|
|
90
|
+
|
|
91
|
+
#### Trading Operations
|
|
92
|
+
|
|
93
|
+
```typescript
|
|
94
|
+
import {
|
|
95
|
+
createTradersPortalService,
|
|
96
|
+
buildPositionRequestIdentifier,
|
|
97
|
+
buildPositionRequestParams,
|
|
98
|
+
TOpenOrderType
|
|
99
|
+
} from 'lynx-client';
|
|
100
|
+
|
|
101
|
+
const tradersPortal = createTradersPortalService(signer, tradersPortalAddress);
|
|
102
|
+
|
|
103
|
+
// Build position parameters using human-readable values
|
|
104
|
+
const identifier = buildPositionRequestIdentifier({
|
|
105
|
+
trader: await signer.getAddress(),
|
|
106
|
+
pairId: 1, // BTC/USD
|
|
107
|
+
settlementAsset: "0x...", // USDC address
|
|
108
|
+
positionIndex: 0
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
const params = buildPositionRequestParams({
|
|
112
|
+
isLong: true,
|
|
113
|
+
collateral: 100, // 100 USDC
|
|
114
|
+
leverage: 25, // 25x leverage
|
|
115
|
+
minPrice: 50000, // $50,000
|
|
116
|
+
maxPrice: 50100, // $50,100
|
|
117
|
+
takeProfit: 55000, // $55,000
|
|
118
|
+
stopLoss: 48000 // $48,000
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
// Open a position
|
|
122
|
+
await tradersPortal.traderRequests.openNewPosition(
|
|
123
|
+
identifier,
|
|
124
|
+
params,
|
|
125
|
+
TOpenOrderType.MARKET,
|
|
126
|
+
"0x", // referrer domain
|
|
127
|
+
"0x", // referrer code
|
|
128
|
+
true, // run cap tests
|
|
129
|
+
ethers.parseEther("0.01") // native fee
|
|
130
|
+
);
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
#### Lens Services (Read-Only Data)
|
|
134
|
+
|
|
135
|
+
```typescript
|
|
136
|
+
import { createLexLensService, createTradingFloorLensService } from 'lynx-client';
|
|
137
|
+
|
|
138
|
+
// LEX Pool data
|
|
139
|
+
const lexLens = createLexLensService(provider, lexLensAddress);
|
|
140
|
+
const poolState = await lexLens.getLexPoolState(lexPoolAddress);
|
|
141
|
+
const pairConfigs = await lexLens.getAllPairConfigurationsInLex(lexPoolAddress);
|
|
142
|
+
|
|
143
|
+
// Trading floor data
|
|
144
|
+
const tradingFloorLens = createTradingFloorLensService(provider, tradingFloorLensAddress);
|
|
145
|
+
const position = await tradingFloorLens.getPositionByPositionId(positionId);
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### Utility Functions
|
|
149
|
+
|
|
150
|
+
#### Price Conversions
|
|
151
|
+
|
|
152
|
+
```typescript
|
|
153
|
+
import { floatToPriceBn, priceBnToFloat } from 'lynx-client';
|
|
154
|
+
|
|
155
|
+
// Convert human-readable price to contract format (8 decimals)
|
|
156
|
+
const priceBn = floatToPriceBn(50000.50); // $50,000.50 → BigInt
|
|
157
|
+
|
|
158
|
+
// Convert contract price to human-readable
|
|
159
|
+
const price = priceBnToFloat(priceBn); // BigInt → 50000.50
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
#### Leverage Conversions
|
|
163
|
+
|
|
164
|
+
```typescript
|
|
165
|
+
import { floatUnitsToScaledLeverage, scaledLeverageToUnits } from 'lynx-client';
|
|
166
|
+
|
|
167
|
+
// Convert human leverage to contract format
|
|
168
|
+
const scaledLeverage = floatUnitsToScaledLeverage(25); // 25x → 2500
|
|
169
|
+
|
|
170
|
+
// Convert contract leverage to human-readable
|
|
171
|
+
const leverage = scaledLeverageToUnits(2500); // 2500 → 25x
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
#### Collateral Conversions
|
|
175
|
+
|
|
176
|
+
```typescript
|
|
177
|
+
import { floatToChipsBn, chipsBnToUnits } from 'lynx-client';
|
|
178
|
+
|
|
179
|
+
// Convert human-readable amount to contract format (18 decimals)
|
|
180
|
+
const collateralBn = floatToChipsBn(100.5); // 100.5 tokens → BigInt
|
|
181
|
+
|
|
182
|
+
// Convert contract amount to human-readable
|
|
183
|
+
const collateral = chipsBnToUnits(collateralBn); // BigInt → 100.5
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
#### Fraction Conversions
|
|
187
|
+
|
|
188
|
+
```typescript
|
|
189
|
+
import { floatToFractionBn, fractionBnToFloat } from 'lynx-client';
|
|
190
|
+
|
|
191
|
+
// Convert percentage to contract format
|
|
192
|
+
const fractionBn = floatToFractionBn(0.05); // 5% → 5000
|
|
193
|
+
|
|
194
|
+
// Convert contract fraction to percentage
|
|
195
|
+
const fraction = fractionBnToFloat(5000n); // 5000 → 0.05 (5%)
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
## Advanced Usage
|
|
199
|
+
|
|
200
|
+
### Position Management
|
|
201
|
+
|
|
202
|
+
```typescript
|
|
203
|
+
// Update position with new TP/SL
|
|
204
|
+
await tradersPortal.traderRequests.updatePositionDoubleFieldTpAndSl(
|
|
205
|
+
positionId,
|
|
206
|
+
floatToPriceBn(55000), // New TP: $55,000
|
|
207
|
+
floatToPriceBn(48000), // New SL: $48,000
|
|
208
|
+
ethers.parseEther("0.01") // Fee
|
|
209
|
+
);
|
|
210
|
+
|
|
211
|
+
// Close position at market
|
|
212
|
+
await tradersPortal.traderRequests.setExistingPositionToMarketClose(
|
|
213
|
+
positionId,
|
|
214
|
+
floatToPriceBn(49900), // Min acceptable price
|
|
215
|
+
floatToPriceBn(50100), // Max acceptable price
|
|
216
|
+
ethers.parseEther("0.01") // Fee
|
|
217
|
+
);
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
### Working with Triggers
|
|
221
|
+
|
|
222
|
+
```typescript
|
|
223
|
+
import { createTriggersService } from 'lynx-client';
|
|
224
|
+
|
|
225
|
+
const triggers = createTriggersService(signer, triggersAddress);
|
|
226
|
+
|
|
227
|
+
// Get trigger configurations
|
|
228
|
+
const configs = await triggers.getTriggersConfigurations();
|
|
229
|
+
const pairConfigs = await triggers.getPairConfigsInTriggers(1); // Pair ID 1
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
### LEX Pool Operations
|
|
233
|
+
|
|
234
|
+
```typescript
|
|
235
|
+
// Get complete LEX pool state
|
|
236
|
+
const completeState = await lexLens.getCompleteStateForLex(lexPoolAddress);
|
|
237
|
+
|
|
238
|
+
// Get supplier state
|
|
239
|
+
const supplierState = await lexLens.getLexPoolSupplierState(
|
|
240
|
+
lexPoolAddress,
|
|
241
|
+
supplierAddress
|
|
242
|
+
);
|
|
243
|
+
|
|
244
|
+
// Get all fee configurations
|
|
245
|
+
const feeConfigs = await lexLens.getAllFeeConfigurationsInLex(lexPoolAddress);
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
## Type Safety
|
|
249
|
+
|
|
250
|
+
The SDK provides comprehensive TypeScript types for all contract interactions:
|
|
251
|
+
|
|
252
|
+
```typescript
|
|
253
|
+
import {
|
|
254
|
+
TPositionRequestIdentifierStruct,
|
|
255
|
+
TPositionRequestParamsStruct,
|
|
256
|
+
TSinglePositionStruct,
|
|
257
|
+
TPairConfigsInTriggersStruct
|
|
258
|
+
} from 'lynx-client';
|
|
259
|
+
|
|
260
|
+
// All contract structs are properly typed
|
|
261
|
+
const position: TSinglePositionStruct = await tradingFloorLens.getPositionByPositionId(id);
|
|
262
|
+
console.log(position.trader); // string
|
|
263
|
+
console.log(position.collateral); // bigint
|
|
264
|
+
console.log(position.leverage); // bigint
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
## Error Handling
|
|
268
|
+
|
|
269
|
+
The SDK validates inputs to prevent common errors:
|
|
270
|
+
|
|
271
|
+
```typescript
|
|
272
|
+
try {
|
|
273
|
+
// This will throw an error - can't use both price and fraction TP
|
|
274
|
+
const params = buildPositionRequestParams({
|
|
275
|
+
isLong: true,
|
|
276
|
+
collateral: 100,
|
|
277
|
+
leverage: 25,
|
|
278
|
+
minPrice: 50000,
|
|
279
|
+
maxPrice: 50100,
|
|
280
|
+
takeProfit: 55000, // Price-based TP
|
|
281
|
+
takeProfitByFraction: 0.1 // Fraction-based TP - ERROR!
|
|
282
|
+
});
|
|
283
|
+
} catch (error) {
|
|
284
|
+
console.error("Cannot specify both takeProfit and takeProfitByFraction");
|
|
285
|
+
}
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
## Constants and Enums
|
|
289
|
+
|
|
290
|
+
```typescript
|
|
291
|
+
import {
|
|
292
|
+
TOpenOrderType,
|
|
293
|
+
TOrderCloseType,
|
|
294
|
+
TPositionField,
|
|
295
|
+
TPairIds,
|
|
296
|
+
CHIP_DECIMALS,
|
|
297
|
+
PRICES_SCALE,
|
|
298
|
+
LEVERAGE_MULTIPLIER_SCALE
|
|
299
|
+
} from 'lynx-client';
|
|
300
|
+
|
|
301
|
+
// Order types
|
|
302
|
+
const marketOrder = TOpenOrderType.MARKET;
|
|
303
|
+
const limitOrder = TOpenOrderType.LIMIT;
|
|
304
|
+
|
|
305
|
+
// Pair IDs
|
|
306
|
+
const btcUsd = TPairIds.BTC_USD;
|
|
307
|
+
const ethUsd = TPairIds.ETH_USD;
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
## Best Practices
|
|
311
|
+
|
|
312
|
+
1. **Always use builder functions** for creating position requests:
|
|
313
|
+
```typescript
|
|
314
|
+
// ✅ Good
|
|
315
|
+
const params = buildPositionRequestParams({ ... });
|
|
316
|
+
|
|
317
|
+
// ❌ Avoid manual construction
|
|
318
|
+
const params = { long: true, collateral: 100n, ... };
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
2. **Use utility functions** for conversions:
|
|
322
|
+
```typescript
|
|
323
|
+
// ✅ Good
|
|
324
|
+
const priceBn = floatToPriceBn(50000);
|
|
325
|
+
|
|
326
|
+
// ❌ Avoid manual calculations
|
|
327
|
+
const priceBn = BigInt(50000 * 10**8);
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
3. **Handle contract errors** appropriately:
|
|
331
|
+
```typescript
|
|
332
|
+
try {
|
|
333
|
+
await tradersPortal.traderRequests.openNewPosition(...);
|
|
334
|
+
} catch (error) {
|
|
335
|
+
if (error.reason === "Insufficient collateral") {
|
|
336
|
+
// Handle specific error
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
## Development
|
|
342
|
+
|
|
343
|
+
### Building
|
|
344
|
+
|
|
345
|
+
```bash
|
|
346
|
+
npm run build
|
|
347
|
+
```
|
|
348
|
+
|
|
349
|
+
### Testing
|
|
350
|
+
|
|
351
|
+
```bash
|
|
352
|
+
npm test
|
|
353
|
+
```
|
|
354
|
+
|
|
355
|
+
### Contributing
|
|
356
|
+
|
|
357
|
+
1. Fork the repository
|
|
358
|
+
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
|
|
359
|
+
3. Commit your changes (`git commit -m 'Add some amazing feature'`)
|
|
360
|
+
4. Push to the branch (`git push origin feature/amazing-feature`)
|
|
361
|
+
5. Open a Pull Request
|
|
362
|
+
|
|
363
|
+
## License
|
|
364
|
+
|
|
365
|
+
ISC
|
|
366
|
+
|
|
367
|
+
## Support
|
|
368
|
+
|
|
369
|
+
- [GitHub Issues](https://github.com/lynx-protocol/lynx-client/issues)
|
|
370
|
+
- [Documentation](https://lynx-finance.gitbook.io/lynx-finance/)
|
|
371
|
+
- [Discord](https://discord.gg/4CGxEYwrF2)
|
package/dist/cjs/index.js
CHANGED
|
@@ -51,3 +51,5 @@ __exportStar(require("./lib/typechain/factories/contracts/Peripheral/Lens/Intent
|
|
|
51
51
|
__exportStar(require("./lib/typechain/factories/contracts/Peripheral/Lens/TriggersAndPortalLens__factory"), exports);
|
|
52
52
|
__exportStar(require("./lib/typechain/factories/contracts/Peripheral/Lens/LexLens__factory"), exports);
|
|
53
53
|
__exportStar(require("./lib/typechain/factories/contracts/Peripheral/Lens/TradingFloorLens__factory"), exports);
|
|
54
|
+
// Developer Experience utilities
|
|
55
|
+
__exportStar(require("./lib/devex"), exports);
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ENGINE_CHAIN_DISPLAY_NAME = exports.ENGINE_CHAIN_ID_BY_NAME = void 0;
|
|
4
|
+
const chainConstants_1 = require("./chainConstants");
|
|
5
|
+
// Engine chain mappings
|
|
6
|
+
exports.ENGINE_CHAIN_ID_BY_NAME = {
|
|
7
|
+
sonic: chainConstants_1.CHAIN_ID_SONIC,
|
|
8
|
+
boba: chainConstants_1.CHAIN_ID_BOBA,
|
|
9
|
+
flare: chainConstants_1.CHAIN_ID_FLARE,
|
|
10
|
+
fantom: chainConstants_1.CHAIN_ID_FANTOM,
|
|
11
|
+
};
|
|
12
|
+
exports.ENGINE_CHAIN_DISPLAY_NAME = {
|
|
13
|
+
sonic: "Sonic",
|
|
14
|
+
boba: "Boba",
|
|
15
|
+
flare: "Flare",
|
|
16
|
+
fantom: "Fantom",
|
|
17
|
+
};
|
|
@@ -2,16 +2,36 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.OrderBookService = void 0;
|
|
4
4
|
const OrderBookV1__factory_1 = require("../../typechain/factories/contracts/Lynx/OrderBook/OrderBookV1__factory");
|
|
5
|
-
class
|
|
6
|
-
constructor(
|
|
7
|
-
this.
|
|
8
|
-
this.orderBookContract = OrderBookV1__factory_1.OrderBookV1__factory.connect(address, signerOrProvider);
|
|
5
|
+
class OrderManagement {
|
|
6
|
+
constructor(orderBookContract) {
|
|
7
|
+
this.orderBookContract = orderBookContract;
|
|
9
8
|
}
|
|
10
|
-
// Order Management
|
|
11
9
|
async getAllPendingUpdateOrderIds() {
|
|
12
10
|
return this.orderBookContract.getAllPendingUpdateOrderIds();
|
|
13
11
|
}
|
|
14
|
-
|
|
12
|
+
async allPendingUpdateOrderIds(index) {
|
|
13
|
+
return this.orderBookContract.allPendingUpdateOrderIds(index);
|
|
14
|
+
}
|
|
15
|
+
async pendingUpdateTradeFieldOrdersById(positionId) {
|
|
16
|
+
return this.orderBookContract.pendingUpdateTradeFieldOrdersById(positionId);
|
|
17
|
+
}
|
|
18
|
+
async readAndDeleteUpdatePositionOrder(positionId) {
|
|
19
|
+
return this.orderBookContract.readAndDeleteUpdatePositionOrder(positionId);
|
|
20
|
+
}
|
|
21
|
+
async storeUpdatePositionDoubleFieldOrder(positionId, orderType, fieldValueA, fieldValueB) {
|
|
22
|
+
return this.orderBookContract.storeUpdatePositionDoubleFieldOrder(positionId, orderType, fieldValueA, fieldValueB);
|
|
23
|
+
}
|
|
24
|
+
async storeUpdatePositionSingleFieldOrder(positionId, orderType, fieldValue) {
|
|
25
|
+
return this.orderBookContract.storeUpdatePositionSingleFieldOrder(positionId, orderType, fieldValue);
|
|
26
|
+
}
|
|
27
|
+
async updateOrderIdPositionInList(positionId) {
|
|
28
|
+
return this.orderBookContract.updateOrderIdPositionInList(positionId);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
class ContractInfo {
|
|
32
|
+
constructor(orderBookContract) {
|
|
33
|
+
this.orderBookContract = orderBookContract;
|
|
34
|
+
}
|
|
15
35
|
async registry() {
|
|
16
36
|
return this.orderBookContract.registry();
|
|
17
37
|
}
|
|
@@ -30,7 +50,22 @@ class OrderBookService {
|
|
|
30
50
|
async pendingImplementation() {
|
|
31
51
|
return this.orderBookContract.pendingImplementation();
|
|
32
52
|
}
|
|
33
|
-
|
|
53
|
+
}
|
|
54
|
+
class Administration {
|
|
55
|
+
constructor(orderBookContract) {
|
|
56
|
+
this.orderBookContract = orderBookContract;
|
|
57
|
+
}
|
|
58
|
+
async setTradingFloor(tradingFloor) {
|
|
59
|
+
return this.orderBookContract.setTradingFloor(tradingFloor);
|
|
60
|
+
}
|
|
61
|
+
async _become(orderBookProxy) {
|
|
62
|
+
return this.orderBookContract._become(orderBookProxy);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
class Constants {
|
|
66
|
+
constructor(orderBookContract) {
|
|
67
|
+
this.orderBookContract = orderBookContract;
|
|
68
|
+
}
|
|
34
69
|
async ACCURACY_IMPROVEMENT_SCALE() {
|
|
35
70
|
return this.orderBookContract.ACCURACY_IMPROVEMENT_SCALE();
|
|
36
71
|
}
|
|
@@ -44,4 +79,14 @@ class OrderBookService {
|
|
|
44
79
|
return this.orderBookContract.PRECISION();
|
|
45
80
|
}
|
|
46
81
|
}
|
|
82
|
+
class OrderBookService {
|
|
83
|
+
constructor(address, signerOrProvider) {
|
|
84
|
+
this.signerOrProvider = signerOrProvider;
|
|
85
|
+
this.orderBookContract = OrderBookV1__factory_1.OrderBookV1__factory.connect(address, signerOrProvider);
|
|
86
|
+
this.orderManagement = new OrderManagement(this.orderBookContract);
|
|
87
|
+
this.contractInfo = new ContractInfo(this.orderBookContract);
|
|
88
|
+
this.administration = new Administration(this.orderBookContract);
|
|
89
|
+
this.constants = new Constants(this.orderBookContract);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
47
92
|
exports.OrderBookService = OrderBookService;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getChainAddresses = getChainAddresses;
|
|
4
|
+
const systemAddresses_1 = require("../addresses/systemAddresses");
|
|
5
|
+
const lensAddresses_1 = require("../addresses/lensAddresses");
|
|
6
|
+
const deployedContractsConnector_1 = require("../contractsIntegration/deployedContractsConnector");
|
|
7
|
+
const chainMappings_1 = require("../chains/chainMappings");
|
|
8
|
+
/**
|
|
9
|
+
* Get all Lynx system contract addresses for a specific chain
|
|
10
|
+
* @param options - Chain ID and provider
|
|
11
|
+
* @returns Promise<ILynxChainAddresses> - All system contract addresses
|
|
12
|
+
* @throws Error if chain is not supported
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* import { getChainAddresses } from 'lynx-client/devex';
|
|
17
|
+
* import { ethers } from 'ethers';
|
|
18
|
+
*
|
|
19
|
+
* const provider = new ethers.JsonRpcProvider('https://rpc.example.com');
|
|
20
|
+
* const addresses = await getChainAddresses({ chainId: 146, provider });
|
|
21
|
+
*
|
|
22
|
+
* console.log(addresses.tradingFloorAddress); // Address of TradingFloor contract
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
async function getChainAddresses(options) {
|
|
26
|
+
const { chainId, provider } = options;
|
|
27
|
+
// Find the chain configuration
|
|
28
|
+
const chainEntry = Object.entries(chainMappings_1.ENGINE_CHAIN_ID_BY_NAME).find(([_, id]) => id === chainId);
|
|
29
|
+
if (!chainEntry) {
|
|
30
|
+
throw new Error(`Chain ID ${chainId} is not supported by Lynx protocol engine chains`);
|
|
31
|
+
}
|
|
32
|
+
const [chainKey] = chainEntry;
|
|
33
|
+
const addresses = systemAddresses_1.LynxSystemAddresses[chainKey];
|
|
34
|
+
const lensAddresses = lensAddresses_1.LensAddresses[chainKey];
|
|
35
|
+
const chainName = chainMappings_1.ENGINE_CHAIN_DISPLAY_NAME[chainKey];
|
|
36
|
+
// Connect to registry to get current implementation addresses
|
|
37
|
+
const registry = (0, deployedContractsConnector_1.connectToLatestRegistry)(provider, addresses.registryProxyAddress);
|
|
38
|
+
try {
|
|
39
|
+
// Fetch all contract addresses from registry
|
|
40
|
+
const [tradersPortal, orderBook, triggers,] = await Promise.all([
|
|
41
|
+
registry.tradersPortal(),
|
|
42
|
+
registry.orderBook(),
|
|
43
|
+
registry.triggers(),
|
|
44
|
+
]);
|
|
45
|
+
// Get registry implementation
|
|
46
|
+
const registryImplementation = await registry.implementation();
|
|
47
|
+
return {
|
|
48
|
+
chainId,
|
|
49
|
+
chainName,
|
|
50
|
+
registryProxyAddress: addresses.registryProxyAddress,
|
|
51
|
+
registryImplementationAddress: registryImplementation,
|
|
52
|
+
tradersPortalAddress: tradersPortal,
|
|
53
|
+
tradingFloorAddress: addresses.tradingFloorProxyAddress,
|
|
54
|
+
orderBookAddress: orderBook,
|
|
55
|
+
triggersAddress: triggers,
|
|
56
|
+
lexLensAddress: lensAddresses.lexLens,
|
|
57
|
+
tradingFloorLensAddress: lensAddresses.tradingFloorLensLens,
|
|
58
|
+
intentsVerifierLensAddress: lensAddresses.intentsVerifierLens,
|
|
59
|
+
triggersAndPortalLensAddress: lensAddresses.triggersAndPortalLens,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
throw new Error(`Failed to fetch addresses from registry on chain ${chainId}: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getSupportedEngineChains = getSupportedEngineChains;
|
|
4
|
+
exports.isEngineChainId = isEngineChainId;
|
|
5
|
+
const systemAddresses_1 = require("../addresses/systemAddresses");
|
|
6
|
+
const chainMappings_1 = require("../chains/chainMappings");
|
|
7
|
+
/**
|
|
8
|
+
* Get all chains supported by the Lynx protocol
|
|
9
|
+
* @returns Array of supported chains with their details
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* import { getSupportedChains } from 'lynx-client/devex';
|
|
14
|
+
*
|
|
15
|
+
* const chains = getSupportedChains();
|
|
16
|
+
* chains.forEach(chain => {
|
|
17
|
+
* console.log(`${chain.chainName} (${chain.chainId}): ${chain.registryProxyAddress}`);
|
|
18
|
+
* });
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
function getSupportedEngineChains() {
|
|
22
|
+
return Object.entries(systemAddresses_1.LynxSystemAddresses).map(([chainKey, config]) => ({
|
|
23
|
+
chainId: chainMappings_1.ENGINE_CHAIN_ID_BY_NAME[chainKey],
|
|
24
|
+
chainName: chainMappings_1.ENGINE_CHAIN_DISPLAY_NAME[chainKey] || chainKey,
|
|
25
|
+
chainKey,
|
|
26
|
+
registryProxyAddress: config.registryProxyAddress,
|
|
27
|
+
}));
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Check if a chain is supported by the Lynx protocol
|
|
31
|
+
* @param chainId - The chain ID to check
|
|
32
|
+
* @returns boolean - true if supported, false otherwise
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```typescript
|
|
36
|
+
* import { isChainSupported } from 'lynx-client/devex';
|
|
37
|
+
*
|
|
38
|
+
* if (isChainSupported(146)) {
|
|
39
|
+
* console.log('Sonic chain is supported!');
|
|
40
|
+
* }
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
function isEngineChainId(chainId) {
|
|
44
|
+
return Object.values(chainMappings_1.ENGINE_CHAIN_ID_BY_NAME).includes(chainId);
|
|
45
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isEngineChainId = exports.getSupportedEngineChains = exports.getChainAddresses = void 0;
|
|
4
|
+
// Developer Experience utilities
|
|
5
|
+
var getChainAddresses_1 = require("./getChainAddresses");
|
|
6
|
+
Object.defineProperty(exports, "getChainAddresses", { enumerable: true, get: function () { return getChainAddresses_1.getChainAddresses; } });
|
|
7
|
+
var getSupportedEngineChains_1 = require("./getSupportedEngineChains");
|
|
8
|
+
Object.defineProperty(exports, "getSupportedEngineChains", { enumerable: true, get: function () { return getSupportedEngineChains_1.getSupportedEngineChains; } });
|
|
9
|
+
Object.defineProperty(exports, "isEngineChainId", { enumerable: true, get: function () { return getSupportedEngineChains_1.isEngineChainId; } });
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -35,4 +35,5 @@ export * from "./lib/typechain/factories/contracts/Peripheral/Lens/IntentsVerifi
|
|
|
35
35
|
export * from "./lib/typechain/factories/contracts/Peripheral/Lens/TriggersAndPortalLens__factory";
|
|
36
36
|
export * from "./lib/typechain/factories/contracts/Peripheral/Lens/LexLens__factory";
|
|
37
37
|
export * from "./lib/typechain/factories/contracts/Peripheral/Lens/TradingFloorLens__factory";
|
|
38
|
+
export * from "./lib/devex";
|
|
38
39
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/esm/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../index.ts"],"names":[],"mappings":"AAAA,cAAc,6BAA6B,CAAC;AAC5C,cAAc,yBAAyB,CAAC;AAExC,cAAc,uBAAuB,CAAC;AACtC,cAAc,wBAAwB,CAAC;AACvC,cAAc,yCAAyC,CAAC;AACxD,cAAc,4CAA4C,CAAC;AAC3D,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,yBAAyB,CAAC;AACxC,cAAc,kCAAkC,CAAC;AACjD,cAAc,mBAAmB,CAAC;AAClC,cAAc,2CAA2C,CAAC;AAE1D,cAAc,+BAA+B,CAAC;AAC9C,cAAc,kCAAkC,CAAC;AACjD,cAAc,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC;AACxC,cAAc,0BAA0B,CAAC;AACzC,cAAc,wBAAwB,CAAC;AAEvC,cAAc,yCAAyC,CAAC;AACxD,cAAc,yCAAyC,CAAC;AAExD,cAAc,+BAA+B,CAAC;AAC9C,cAAc,iCAAiC,CAAC;AAEhD,cAAc,uDAAuD,CAAC;AAEtE,cAAc,iDAAiD,CAAC;AAEhE,cAAc,uDAAuD,CAAC;AACtE,cAAc,yDAAyD,CAAC;AACxE,cAAc,oDAAoD,CAAC;AACnE,cAAc,2CAA2C,CAAC;AAE1D,cAAc,+DAA+D,CAAC;AAC9E,cAAc,iEAAiE,CAAC;AAChF,cAAc,mDAAmD,CAAC;AAClE,cAAc,4DAA4D,CAAC;AAE3E,cAAc,kFAAkF,CAAC;AACjG,cAAc,oFAAoF,CAAC;AACnG,cAAc,sEAAsE,CAAC;AACrF,cAAc,+EAA+E,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../index.ts"],"names":[],"mappings":"AAAA,cAAc,6BAA6B,CAAC;AAC5C,cAAc,yBAAyB,CAAC;AAExC,cAAc,uBAAuB,CAAC;AACtC,cAAc,wBAAwB,CAAC;AACvC,cAAc,yCAAyC,CAAC;AACxD,cAAc,4CAA4C,CAAC;AAC3D,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,yBAAyB,CAAC;AACxC,cAAc,kCAAkC,CAAC;AACjD,cAAc,mBAAmB,CAAC;AAClC,cAAc,2CAA2C,CAAC;AAE1D,cAAc,+BAA+B,CAAC;AAC9C,cAAc,kCAAkC,CAAC;AACjD,cAAc,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC;AACxC,cAAc,0BAA0B,CAAC;AACzC,cAAc,wBAAwB,CAAC;AAEvC,cAAc,yCAAyC,CAAC;AACxD,cAAc,yCAAyC,CAAC;AAExD,cAAc,+BAA+B,CAAC;AAC9C,cAAc,iCAAiC,CAAC;AAEhD,cAAc,uDAAuD,CAAC;AAEtE,cAAc,iDAAiD,CAAC;AAEhE,cAAc,uDAAuD,CAAC;AACtE,cAAc,yDAAyD,CAAC;AACxE,cAAc,oDAAoD,CAAC;AACnE,cAAc,2CAA2C,CAAC;AAE1D,cAAc,+DAA+D,CAAC;AAC9E,cAAc,iEAAiE,CAAC;AAChF,cAAc,mDAAmD,CAAC;AAClE,cAAc,4DAA4D,CAAC;AAE3E,cAAc,kFAAkF,CAAC;AACjG,cAAc,oFAAoF,CAAC;AACnG,cAAc,sEAAsE,CAAC;AACrF,cAAc,+EAA+E,CAAC;AAG9F,cAAc,aAAa,CAAC"}
|
package/dist/esm/index.js
CHANGED
|
@@ -51,3 +51,5 @@ __exportStar(require("./lib/typechain/factories/contracts/Peripheral/Lens/Intent
|
|
|
51
51
|
__exportStar(require("./lib/typechain/factories/contracts/Peripheral/Lens/TriggersAndPortalLens__factory"), exports);
|
|
52
52
|
__exportStar(require("./lib/typechain/factories/contracts/Peripheral/Lens/LexLens__factory"), exports);
|
|
53
53
|
__exportStar(require("./lib/typechain/factories/contracts/Peripheral/Lens/TradingFloorLens__factory"), exports);
|
|
54
|
+
// Developer Experience utilities
|
|
55
|
+
__exportStar(require("./lib/devex"), exports);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare const ENGINE_CHAIN_ID_BY_NAME: {
|
|
2
|
+
readonly sonic: 146;
|
|
3
|
+
readonly boba: 288;
|
|
4
|
+
readonly flare: 14;
|
|
5
|
+
readonly fantom: 250;
|
|
6
|
+
};
|
|
7
|
+
export declare const ENGINE_CHAIN_DISPLAY_NAME: {
|
|
8
|
+
readonly sonic: "Sonic";
|
|
9
|
+
readonly boba: "Boba";
|
|
10
|
+
readonly flare: "Flare";
|
|
11
|
+
readonly fantom: "Fantom";
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=chainMappings.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chainMappings.d.ts","sourceRoot":"","sources":["../../../../lib/chains/chainMappings.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,uBAAuB;;;;;CAK1B,CAAC;AAEX,eAAO,MAAM,yBAAyB;;;;;CAK5B,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ENGINE_CHAIN_DISPLAY_NAME = exports.ENGINE_CHAIN_ID_BY_NAME = void 0;
|
|
4
|
+
const chainConstants_1 = require("./chainConstants");
|
|
5
|
+
// Engine chain mappings
|
|
6
|
+
exports.ENGINE_CHAIN_ID_BY_NAME = {
|
|
7
|
+
sonic: chainConstants_1.CHAIN_ID_SONIC,
|
|
8
|
+
boba: chainConstants_1.CHAIN_ID_BOBA,
|
|
9
|
+
flare: chainConstants_1.CHAIN_ID_FLARE,
|
|
10
|
+
fantom: chainConstants_1.CHAIN_ID_FANTOM,
|
|
11
|
+
};
|
|
12
|
+
exports.ENGINE_CHAIN_DISPLAY_NAME = {
|
|
13
|
+
sonic: "Sonic",
|
|
14
|
+
boba: "Boba",
|
|
15
|
+
flare: "Flare",
|
|
16
|
+
fantom: "Fantom",
|
|
17
|
+
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { CHAIN_ID_ETHEREUM, CHAIN_ID_OPTIMISM, CHAIN_ID_BSC, CHAIN_ID_FANTOM, CHAIN_ID_POLYGON, CHAIN_ID_BOBA, CHAIN_ID_MANTLE, CHAIN_ID_LINEA, CHAIN_ID_FUSE, CHAIN_ID_ARBITRUM, CHAIN_ID_CELO, CHAIN_ID_MODE, CHAIN_ID_ZIRCUIT, CHAIN_ID_BASE, CHAIN_ID_GOAT, CHAIN_ID_SONIC, CHAIN_ID_FLARE } from "./chainConstants";
|
|
2
|
+
import { ENGINE_CHAIN_ID_BY_NAME } from "./chainMappings";
|
|
2
3
|
export type TSourceChainIds = typeof CHAIN_ID_FUSE | typeof CHAIN_ID_LINEA | typeof CHAIN_ID_ARBITRUM | typeof CHAIN_ID_OPTIMISM | typeof CHAIN_ID_POLYGON | typeof CHAIN_ID_MANTLE | typeof CHAIN_ID_BSC | typeof CHAIN_ID_MODE | typeof CHAIN_ID_CELO | typeof CHAIN_ID_ZIRCUIT | typeof CHAIN_ID_BASE | typeof CHAIN_ID_ETHEREUM | typeof CHAIN_ID_GOAT;
|
|
3
4
|
export type TEngineChainIds = typeof CHAIN_ID_FANTOM | typeof CHAIN_ID_SONIC | typeof CHAIN_ID_BOBA | typeof CHAIN_ID_FLARE;
|
|
4
5
|
export type TLiveChainIds = TSourceChainIds | TEngineChainIds;
|
|
@@ -7,4 +8,6 @@ export type TEngineChainNames = "fantom" | "boba" | "sonic" | "flare";
|
|
|
7
8
|
export type TSourceChainNames = "ethereum" | "bsc" | "fantom" | "fuse" | "optimism" | "polygon" | "arbitrum" | "celo" | "maticMainnet" | "avalanche" | "boba" | "mantle" | "mode" | "linea" | "zircuit" | "base" | "goat";
|
|
8
9
|
export type TChainNames = TEngineChainNames | TSourceChainNames;
|
|
9
10
|
export declare const CHAIN_ID_TO_NAME: Record<TChainIds, TChainNames>;
|
|
11
|
+
export type EngineChainKey = keyof typeof ENGINE_CHAIN_ID_BY_NAME;
|
|
12
|
+
export type EngineChainId = typeof ENGINE_CHAIN_ID_BY_NAME[EngineChainKey];
|
|
10
13
|
//# sourceMappingURL=chainTypes.d.ts.map
|