lynx-client 0.0.1-beta.12 → 0.0.1-beta.14
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/IntentsVerifierLensService/IntentsVerifierLensService.js +2 -2
- package/dist/cjs/lib/contractsIntegration/LexLensService/LexLensService.js +3 -23
- package/dist/cjs/lib/contractsIntegration/OrderBookService/OrderBookService.js +52 -7
- package/dist/cjs/lib/contractsIntegration/TradingFloorLensService/TradingFloorLensService.js +22 -7
- package/dist/cjs/lib/contractsIntegration/TriggersAndPortalLensService/TriggersAndPortalLensService.js +2 -2
- package/dist/cjs/lib/contractsIntegration/deployedContractsConnector.js +8 -10
- 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/IntentsVerifierLensService/IntentsVerifierLensService.d.ts +2 -2
- package/dist/esm/lib/contractsIntegration/IntentsVerifierLensService/IntentsVerifierLensService.d.ts.map +1 -1
- package/dist/esm/lib/contractsIntegration/IntentsVerifierLensService/IntentsVerifierLensService.js +2 -2
- package/dist/esm/lib/contractsIntegration/LexLensService/LexLensService.d.ts +2 -3
- package/dist/esm/lib/contractsIntegration/LexLensService/LexLensService.d.ts.map +1 -1
- package/dist/esm/lib/contractsIntegration/LexLensService/LexLensService.js +3 -23
- 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/contractsIntegration/TradingFloorLensService/TradingFloorLensService.d.ts +2 -3
- package/dist/esm/lib/contractsIntegration/TradingFloorLensService/TradingFloorLensService.d.ts.map +1 -1
- package/dist/esm/lib/contractsIntegration/TradingFloorLensService/TradingFloorLensService.js +22 -7
- package/dist/esm/lib/contractsIntegration/TriggersAndPortalLensService/TriggersAndPortalLensService.d.ts +2 -2
- package/dist/esm/lib/contractsIntegration/TriggersAndPortalLensService/TriggersAndPortalLensService.d.ts.map +1 -1
- package/dist/esm/lib/contractsIntegration/TriggersAndPortalLensService/TriggersAndPortalLensService.js +2 -2
- package/dist/esm/lib/contractsIntegration/deployedContractsConnector.d.ts +4 -4
- package/dist/esm/lib/contractsIntegration/deployedContractsConnector.d.ts.map +1 -1
- package/dist/esm/lib/contractsIntegration/deployedContractsConnector.js +8 -10
- 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/IntentsVerifierLensService/IntentsVerifierLensService.d.ts +2 -2
- package/dist/types/lib/contractsIntegration/IntentsVerifierLensService/IntentsVerifierLensService.d.ts.map +1 -1
- package/dist/types/lib/contractsIntegration/LexLensService/LexLensService.d.ts +2 -3
- package/dist/types/lib/contractsIntegration/LexLensService/LexLensService.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/contractsIntegration/TradingFloorLensService/TradingFloorLensService.d.ts +2 -3
- package/dist/types/lib/contractsIntegration/TradingFloorLensService/TradingFloorLensService.d.ts.map +1 -1
- package/dist/types/lib/contractsIntegration/TriggersAndPortalLensService/TriggersAndPortalLensService.d.ts +2 -2
- package/dist/types/lib/contractsIntegration/TriggersAndPortalLensService/TriggersAndPortalLensService.d.ts.map +1 -1
- package/dist/types/lib/contractsIntegration/deployedContractsConnector.d.ts +4 -4
- package/dist/types/lib/contractsIntegration/deployedContractsConnector.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 +1 -1
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 (accepts both provider and signer)
|
|
139
|
+
const lexLens = createLexLensService(signerOrProvider, lexLensAddress);
|
|
140
|
+
const poolState = await lexLens.getLexPoolState(lexPoolAddress);
|
|
141
|
+
const pairConfigs = await lexLens.getAllPairConfigurationsInLex(lexPoolAddress);
|
|
142
|
+
|
|
143
|
+
// Trading floor data (accepts both provider and signer)
|
|
144
|
+
const tradingFloorLens = createTradingFloorLensService(signerOrProvider, tradingFloorLensAddress);
|
|
145
|
+
const position = await tradingFloorLens.getCompletePositionData(tradingFloorAddress, 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 = await tradingFloorLens.getCompletePositionData(tradingFloorAddress, 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
|
+
};
|
package/dist/cjs/lib/contractsIntegration/IntentsVerifierLensService/IntentsVerifierLensService.js
CHANGED
|
@@ -5,8 +5,8 @@ const IntentsVerifierLens__factory_1 = require("../../typechain/factories/contra
|
|
|
5
5
|
const ethersTypes_1 = require("../../utils/ethersTypes");
|
|
6
6
|
const IIntentsVerifierLensService_1 = require("./IIntentsVerifierLensService");
|
|
7
7
|
class IntentsVerifierLensService {
|
|
8
|
-
constructor(
|
|
9
|
-
this.contract = IntentsVerifierLens__factory_1.IntentsVerifierLens__factory.connect(address,
|
|
8
|
+
constructor(signerOrProvider, address) {
|
|
9
|
+
this.contract = IntentsVerifierLens__factory_1.IntentsVerifierLens__factory.connect(address, signerOrProvider);
|
|
10
10
|
}
|
|
11
11
|
async getRequestBuildingInfoForChipsIntentsVerifier(account, actionType) {
|
|
12
12
|
const result = await this.contract.getRequestBuildingInfoForChipsIntentsVerifier(account, BigInt(actionType));
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.LexLensService = void 0;
|
|
4
|
+
const LexLens__factory_1 = require("../../typechain/factories/contracts/Peripheral/Lens/LexLens__factory");
|
|
4
5
|
const ethersTypes_1 = require("../../utils/ethersTypes");
|
|
5
6
|
const ILexLensService_1 = require("./ILexLensService");
|
|
6
7
|
class LexLensService {
|
|
7
|
-
constructor(
|
|
8
|
-
this.contract =
|
|
8
|
+
constructor(signerOrProvider, contractAddress) {
|
|
9
|
+
this.contract = LexLens__factory_1.LexLens__factory.connect(contractAddress, signerOrProvider);
|
|
9
10
|
}
|
|
10
11
|
async getAllFeeConfigurationsInLex(lexPool) {
|
|
11
12
|
const result = await this.contract.getAllFeeConfigurationsInLex(lexPool);
|
|
@@ -245,26 +246,5 @@ class LexLensService {
|
|
|
245
246
|
})),
|
|
246
247
|
};
|
|
247
248
|
}
|
|
248
|
-
convertCompleteStateResult(result) {
|
|
249
|
-
const baseResult = (0, ethersTypes_1.ethersStructResponseToObject)(result, ILexLensService_1.EMPTY_COMPLETE_LEX_STATE, {
|
|
250
|
-
pairsStates: ILexLensService_1.EMPTY_LEX_PAIR_STATE_LENS,
|
|
251
|
-
groupsStates: ILexLensService_1.EMPTY_LEX_GROUP_STATE_LENS,
|
|
252
|
-
}, {
|
|
253
|
-
lexPoolState: ILexLensService_1.EMPTY_LEX_POOL_LENS_STATE,
|
|
254
|
-
poolAccountantState: ILexLensService_1.EMPTY_POOL_ACCOUNTANT_STATE_LENS,
|
|
255
|
-
});
|
|
256
|
-
// Apply number conversions
|
|
257
|
-
return {
|
|
258
|
-
...baseResult,
|
|
259
|
-
pairsStates: baseResult.pairsStates.map(item => ({
|
|
260
|
-
...item,
|
|
261
|
-
pairId: Number(item.pairId),
|
|
262
|
-
})),
|
|
263
|
-
groupsStates: baseResult.groupsStates.map(item => ({
|
|
264
|
-
...item,
|
|
265
|
-
groupId: Number(item.groupId),
|
|
266
|
-
})),
|
|
267
|
-
};
|
|
268
|
-
}
|
|
269
249
|
}
|
|
270
250
|
exports.LexLensService = LexLensService;
|
|
@@ -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;
|
package/dist/cjs/lib/contractsIntegration/TradingFloorLensService/TradingFloorLensService.js
CHANGED
|
@@ -1,24 +1,35 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TradingFloorLensService = void 0;
|
|
4
|
+
const TradingFloorLens__factory_1 = require("../../typechain/factories/contracts/Peripheral/Lens/TradingFloorLens__factory");
|
|
4
5
|
class TradingFloorLensService {
|
|
5
|
-
constructor(
|
|
6
|
-
this.contract =
|
|
6
|
+
constructor(signerOrProvider, contractAddress) {
|
|
7
|
+
this.contract = TradingFloorLens__factory_1.TradingFloorLens__factory.connect(contractAddress, signerOrProvider);
|
|
7
8
|
}
|
|
8
9
|
async generatePositionHashId(settlementAsset, trader, pairId, index) {
|
|
9
10
|
return await this.contract.generatePositionHashId(settlementAsset, trader, pairId, index);
|
|
10
11
|
}
|
|
11
12
|
async getAllPositionsDataForAllTraders(params) {
|
|
12
13
|
// @ts-ignore
|
|
13
|
-
|
|
14
|
+
const result = await this.contract.getAllPositionsDataForAllTraders.staticCall(params);
|
|
15
|
+
// Filter out empty positions (collateral = 0)
|
|
16
|
+
const filteredPositions = result.positions.filter((pos) => pos.collateral > 0n);
|
|
17
|
+
return {
|
|
18
|
+
...result,
|
|
19
|
+
positions: filteredPositions
|
|
20
|
+
};
|
|
14
21
|
}
|
|
15
22
|
async getAllPositionsDataForAllTradersInDimension(tradingFloor, settlementAsset, arraySize) {
|
|
16
23
|
// @ts-ignore
|
|
17
|
-
|
|
24
|
+
const result = await this.contract.getAllPositionsDataForAllTradersInDimension.staticCall(tradingFloor, settlementAsset, arraySize);
|
|
25
|
+
// Filter out empty positions (collateral = 0)
|
|
26
|
+
return result.filter((pos) => pos.collateral > 0n);
|
|
18
27
|
}
|
|
19
28
|
async getAllPositionsDataForTraderInDimension(tradingFloor, settlementAsset, trader) {
|
|
20
29
|
// @ts-ignore
|
|
21
|
-
|
|
30
|
+
const result = await this.contract.getAllPositionsDataForTraderInDimension.staticCall(tradingFloor, settlementAsset, trader);
|
|
31
|
+
// Filter out empty positions (collateral = 0)
|
|
32
|
+
return result.filter((pos) => pos.collateral > 0n);
|
|
22
33
|
}
|
|
23
34
|
async getAllPositionsLiquidationInfo(params, phases) {
|
|
24
35
|
if (phases !== undefined) {
|
|
@@ -36,11 +47,15 @@ class TradingFloorLensService {
|
|
|
36
47
|
}
|
|
37
48
|
async getPositionDataInPairsForTrader(tradingFloor, settlementAsset, trader, pairIds) {
|
|
38
49
|
// @ts-ignore
|
|
39
|
-
|
|
50
|
+
const result = await this.contract.getPositionDataInPairsForTrader.staticCall(tradingFloor, settlementAsset, trader, pairIds);
|
|
51
|
+
// Filter out empty positions (collateral = 0)
|
|
52
|
+
return result.filter((pos) => pos.collateral > 0n);
|
|
40
53
|
}
|
|
41
54
|
async getPositionsDataInPairForTrader(tradingFloor, settlementAsset, trader, pairId) {
|
|
42
55
|
// @ts-ignore
|
|
43
|
-
|
|
56
|
+
const result = await this.contract.getPositionsDataInPairForTrader.staticCall(tradingFloor, settlementAsset, trader, pairId);
|
|
57
|
+
// Filter out empty positions (collateral = 0)
|
|
58
|
+
return result.filter((pos) => pos.collateral > 0n);
|
|
44
59
|
}
|
|
45
60
|
async getTradingFloorTradeParams(tradingFloor) {
|
|
46
61
|
return await this.contract.getTradingFloorTradeParams(tradingFloor);
|
|
@@ -5,8 +5,8 @@ const TriggersAndPortalLens__factory_1 = require("../../typechain/factories/cont
|
|
|
5
5
|
const ethersTypes_1 = require("../../utils/ethersTypes");
|
|
6
6
|
const ITriggersAndPortalLensService_1 = require("./ITriggersAndPortalLensService");
|
|
7
7
|
class TriggersAndPortalLensService {
|
|
8
|
-
constructor(
|
|
9
|
-
this.contract = TriggersAndPortalLens__factory_1.TriggersAndPortalLens__factory.connect(address,
|
|
8
|
+
constructor(signerOrProvider, address) {
|
|
9
|
+
this.contract = TriggersAndPortalLens__factory_1.TriggersAndPortalLens__factory.connect(address, signerOrProvider);
|
|
10
10
|
}
|
|
11
11
|
async getPairConfigsInTriggers(triggers, pairId) {
|
|
12
12
|
const result = await this.contract.getPairConfigsInTriggers(triggers, BigInt(pairId));
|
|
@@ -119,17 +119,15 @@ function connectToLeXLens(provider, address) {
|
|
|
119
119
|
//
|
|
120
120
|
// ***** Lens Services *****
|
|
121
121
|
//
|
|
122
|
-
function createIntentsVerifierLensService(
|
|
123
|
-
return new IntentsVerifierLensService_1.IntentsVerifierLensService(
|
|
122
|
+
function createIntentsVerifierLensService(signerOrProvider, address) {
|
|
123
|
+
return new IntentsVerifierLensService_1.IntentsVerifierLensService(signerOrProvider, address);
|
|
124
124
|
}
|
|
125
|
-
function createTriggersAndPortalLensService(
|
|
126
|
-
return new TriggersAndPortalLensService_1.TriggersAndPortalLensService(
|
|
125
|
+
function createTriggersAndPortalLensService(signerOrProvider, address) {
|
|
126
|
+
return new TriggersAndPortalLensService_1.TriggersAndPortalLensService(signerOrProvider, address);
|
|
127
127
|
}
|
|
128
|
-
function createTradingFloorLensService(
|
|
129
|
-
|
|
130
|
-
return new TradingFloorLensService_1.TradingFloorLensService(contract);
|
|
128
|
+
function createTradingFloorLensService(signerOrProvider, address) {
|
|
129
|
+
return new TradingFloorLensService_1.TradingFloorLensService(signerOrProvider, address);
|
|
131
130
|
}
|
|
132
|
-
function createLexLensService(
|
|
133
|
-
|
|
134
|
-
return new LexLensService_1.LexLensService(contract);
|
|
131
|
+
function createLexLensService(signerOrProvider, address) {
|
|
132
|
+
return new LexLensService_1.LexLensService(signerOrProvider, address);
|
|
135
133
|
}
|