Skip to content

Commit 6407b60

Browse files
committed
feat: added limit IDs to tradingLimits script
1 parent 2ff1262 commit 6407b60

File tree

8 files changed

+83
-22
lines changed

8 files changed

+83
-22
lines changed

scripts/tradingLimits/README.md

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,12 @@ yarn tradingLimits --exchange BiPoolManager
2626
yarn tradingLimits --exchange=BiPoolManager
2727
yarn tradingLimits -e BiPoolManager
2828

29+
# Show verbose output with Limit IDs
30+
yarn tradingLimits --verbose
31+
yarn tradingLimits -v
32+
2933
# Combine options
30-
yarn tradingLimits --token cUSD --exchange BiPoolManager
34+
yarn tradingLimits --token cUSD --exchange BiPoolManager --verbose
3135

3236
# Connect to a specific RPC endpoint
3337
RPC_URL=https://your-rpc-url.com yarn tradingLimits
@@ -42,6 +46,18 @@ In normal mode, the tool shows a simplified view focused on usability:
4246
- Exchange column shows human-readable format (e.g., "cUSD <-> CELO")
4347
- Technical details like Exchange IDs, Asset addresses, and Limit IDs are hidden
4448

49+
### Verbose Mode
50+
51+
Use the `--verbose` or `-v` flag to enable verbose output:
52+
53+
```bash
54+
yarn tradingLimits --verbose
55+
```
56+
57+
In verbose mode, the tool displays additional technical information:
58+
59+
- **Limit ID** column: Shows the unique identifier for each trading limit (a hex string generated from the exchange ID and asset address using XOR operation)
60+
4561
## Understanding Trading Limits
4662

4763
Mento uses a multi-tiered trading limit system:
@@ -70,6 +86,7 @@ The script produces a table with the following columns:
7086
| Resets In | Time until limit window resets |
7187
| Reset Time | Unix timestamp when limit resets |
7288
| Status | Current status (ACTIVE, INFLOWS BLOCKED, OUTFLOWS BLOCKED, or BLOCKED) |
89+
| Limit ID | Unique identifier for the trading limit (visible in verbose mode only) |
7390

7491
The tool uses color-coded statuses to indicate the current state of each trading limit:
7592

@@ -80,7 +97,7 @@ The tool uses color-coded statuses to indicate the current state of each trading
8097

8198
## Project Structure
8299

83-
```
100+
```text
84101
scripts/tradingLimits/
85102
├── index.ts # Main script entry point
86103
├── types.ts # Type definitions

scripts/tradingLimits/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ async function main(): Promise<void> {
108108
// Display usage information
109109
console.log('\n' + chalk.bold('Usage:'))
110110
console.log(
111-
' yarn tradingLimits [--token|-t <symbol>] [--exchange|-e <exchangeId>] [--network|-n <network>] [--chainId|-c <chainId>]'
111+
' yarn tradingLimits [--token|-t <symbol>] [--exchange|-e <exchangeId>] [--network|-n <network>] [--chainId|-c <chainId>] [--verbose|-v]'
112112
)
113113
console.log('\n' + chalk.bold('Network options:'))
114114
console.log(' --network celo # Celo mainnet')

scripts/tradingLimits/tradingLimitsOrchestrator.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export async function processTradingLimits(
4949
args: ScriptArgs
5050
): Promise<void> {
5151
// Create table for displaying results
52-
const limitsTable = createLimitsTable()
52+
const limitsTable = createLimitsTable(args.verbose)
5353

5454
// Filter exchanges if a token filter is provided
5555
let exchangesToProcess = exchanges
@@ -150,7 +150,8 @@ export async function processTradingLimits(
150150
result.tokenAssets,
151151
result.exchangeName,
152152
limitsTable,
153-
false // Pass false to ensure the exchange name is displayed in the first row for this exchange
153+
false, // Pass false to ensure the exchange name is displayed in the first row for this exchange
154+
args.verbose
154155
)
155156
}
156157
} else {

scripts/tradingLimits/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export interface ScriptArgs {
1414
exchange: string
1515
chainId?: number
1616
rpcUrl?: string
17+
verbose?: boolean
1718
}
1819

1920
// Export types from SDK to avoid importing from multiple places

scripts/tradingLimits/utils/assetLimitProcessor.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
TradingLimitsConfig,
66
TradingLimitsState,
77
} from '../../../src/interfaces'
8+
import { getLimitId } from '../../../src/limits'
89
import { ScriptArgs, TradingLimit } from '../types'
910

1011
/**
@@ -98,6 +99,7 @@ export function getLimitDetails(
9899
*
99100
* @param asset - The token asset
100101
* @param exchangeName - Formatted exchange name
102+
* @param exchangeId - The exchange ID
101103
* @param limits - Trading limits for this asset
102104
* @param configByAsset - Config by asset mapping
103105
* @param stateByAsset - State by asset mapping
@@ -109,6 +111,7 @@ export function getLimitDetails(
109111
export function processAssetWithLimits(
110112
asset: { address: string; symbol: string },
111113
exchangeName: string,
114+
exchangeId: string,
112115
limits: TradingLimit[],
113116
configByAsset: Record<string, TradingLimitsConfig>,
114117
stateByAsset: Record<string, TradingLimitsState>,
@@ -157,6 +160,7 @@ export function processAssetWithLimits(
157160
const row = createLimitRow(
158161
asset,
159162
exchangeName,
163+
exchangeId,
160164
limit,
161165
limitType,
162166
limitValue,
@@ -181,6 +185,7 @@ export function processAssetWithLimits(
181185
const row = createPlaceholderLimitRow(
182186
asset,
183187
exchangeName,
188+
exchangeId,
184189
limitType,
185190
i,
186191
args,
@@ -205,6 +210,7 @@ export function processAssetWithLimits(
205210
*
206211
* @param asset - The token asset
207212
* @param exchangeName - Formatted exchange name
213+
* @param exchangeId - The exchange ID
208214
* @param limit - The trading limit
209215
* @param limitType - The limit type (L0, L1, LG)
210216
* @param limitValue - The limit value
@@ -221,6 +227,7 @@ export function processAssetWithLimits(
221227
export function createLimitRow(
222228
asset: { address: string; symbol: string },
223229
exchangeName: string,
230+
exchangeId: string,
224231
limit: TradingLimit,
225232
limitType: string,
226233
limitValue: number,
@@ -289,6 +296,12 @@ export function createLimitRow(
289296
// Status column
290297
row.push(status)
291298

299+
// Add limit ID column if verbose mode is enabled
300+
if (args.verbose) {
301+
const limitId = getLimitId(exchangeId, asset.address)
302+
row.push(chalk.gray(limitId))
303+
}
304+
292305
// Return the completed row
293306
return row
294307
}
@@ -298,6 +311,7 @@ export function createLimitRow(
298311
*
299312
* @param asset - The token asset
300313
* @param exchangeName - Formatted exchange name
314+
* @param exchangeId - The exchange ID
301315
* @param limitType - The limit type (L0, L1, LG)
302316
* @param limitIndex - The index of this limit
303317
* @param args - Script command line arguments (currently unused but passed through)
@@ -308,6 +322,7 @@ export function createLimitRow(
308322
export function createPlaceholderLimitRow(
309323
asset: { address: string; symbol: string },
310324
exchangeName: string,
325+
exchangeId: string,
311326
limitType: string,
312327
limitIndex: number,
313328
args: ScriptArgs,
@@ -336,6 +351,12 @@ export function createPlaceholderLimitRow(
336351
row.push(chalk.gray('—')) // Max Out
337352
row.push(chalk.gray('NOT CONFIGURED')) // Status
338353

354+
// Add limit ID column if verbose mode is enabled
355+
if (args.verbose) {
356+
const limitId = getLimitId(exchangeId, asset.address)
357+
row.push(chalk.gray(limitId))
358+
}
359+
339360
return row
340361
}
341362

scripts/tradingLimits/utils/exchangeLimitProcessor.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export function processExchangeWithLimits(
4242
processAssetWithLimits(
4343
asset,
4444
exchangeName,
45+
exchange.id,
4546
limits,
4647
exchangeData.configByAsset,
4748
exchangeData.stateByAsset,
@@ -57,7 +58,8 @@ export function processExchangeWithLimits(
5758
[asset],
5859
exchangeName,
5960
limitsTable,
60-
exchangeNameDisplayed
61+
exchangeNameDisplayed,
62+
args.verbose
6163
)
6264

6365
// Mark that we've displayed the exchange name

scripts/tradingLimits/utils/parseCommandLineArgs.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,18 @@ import './typeExtensions'
1414
export function parseCommandLineArgs(): ScriptArgs {
1515
const argv = yargsParser(process.argv.slice(2), {
1616
string: ['token', 'exchange', 'chainId', 'network'],
17+
boolean: ['verbose'],
1718
alias: {
1819
t: 'token',
1920
e: 'exchange',
2021
c: 'chainId',
2122
n: 'network',
23+
v: 'verbose',
2224
},
2325
default: {
2426
token: '',
2527
exchange: '',
28+
verbose: false,
2629
},
2730
configuration: {
2831
'short-option-groups': true,
@@ -38,5 +41,6 @@ export function parseCommandLineArgs(): ScriptArgs {
3841
exchange: argv.exchange,
3942
chainId: networkConfig.chainId,
4043
rpcUrl: networkConfig.rpcUrl,
44+
verbose: argv.verbose,
4145
}
4246
}

scripts/tradingLimits/utils/tableFormatter.ts

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,33 @@ import Table from 'cli-table3'
44
/**
55
* Create a table for displaying trading limits
66
*
7+
* @param verbose - Whether to include the limit ID column
78
* @returns A configured table instance
89
*/
9-
export function createLimitsTable(): Table.Table {
10+
export function createLimitsTable(verbose = false): Table.Table {
1011
// Create table configuration with clean and properly aligned headers
12+
const headers = [
13+
'Exchange',
14+
'Symbol',
15+
'Type',
16+
'Limit',
17+
'Netflow',
18+
'Utilization',
19+
'Timeframe',
20+
'Resets In',
21+
'Reset Time',
22+
'Max In',
23+
'Max Out',
24+
'Status',
25+
]
26+
27+
// Add Limit ID column at the end if verbose mode is enabled
28+
if (verbose) {
29+
headers.push('Limit ID')
30+
}
31+
1132
const tableConfig: Table.TableConstructorOptions = {
12-
head: [
13-
'Exchange',
14-
'Symbol',
15-
'Type',
16-
'Limit',
17-
'Netflow',
18-
'Utilization',
19-
'Timeframe',
20-
'Resets In',
21-
'Reset Time',
22-
'Max In',
23-
'Max Out',
24-
'Status',
25-
],
33+
head: headers,
2634
style: {
2735
head: ['white', 'bold'],
2836
border: ['gray'],
@@ -56,12 +64,14 @@ export function createLimitsTable(): Table.Table {
5664
* @param exchangeName - Formatted exchange name
5765
* @param limitsTable - The table for displaying results
5866
* @param exchangeNameDisplayed - Whether the exchange name has been displayed already
67+
* @param verbose - Whether to include the limit ID column
5968
*/
6069
export function handleExchangeWithNoLimits(
6170
tokenAssets: Array<{ address: string; symbol: string }>,
6271
exchangeName: string,
6372
limitsTable: Table.Table,
64-
exchangeNameDisplayed = false
73+
exchangeNameDisplayed = false,
74+
verbose = false
6575
): void {
6676
// No limits for any assets in this exchange
6777
let isExchangeNameDisplayed = exchangeNameDisplayed
@@ -88,6 +98,11 @@ export function handleExchangeWithNoLimits(
8898
chalk.gray('NO LIMITS CONFIGURED') // Status - changed to match the text from createPlaceholderLimitRow
8999
)
90100

101+
// Add limit ID column if verbose mode is enabled
102+
if (verbose) {
103+
row.push(chalk.gray('—'))
104+
}
105+
91106
limitsTable.push(row)
92107
isExchangeNameDisplayed = true
93108
}

0 commit comments

Comments
 (0)