@arcadia-finance/mcp-server 0.5.2 → 0.6.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 +47 -42
- package/dist/clients/api.js +52 -5
- package/dist/clients/chain.js +1 -1
- package/dist/config/addresses.js +16 -3
- package/dist/index.js +36 -134
- package/dist/prompts/workflows.js +54 -18
- package/dist/resources/guides.js +1 -1
- package/dist/tools/aero.js +157 -0
- package/dist/tools/dev/send.js +4 -4
- package/dist/tools/index.js +6 -0
- package/dist/tools/output-schemas.js +103 -29
- package/dist/tools/read/account.js +13 -13
- package/dist/tools/read/aero-upgrade.js +53 -0
- package/dist/tools/read/asset-managers.js +9 -9
- package/dist/tools/read/assets.js +7 -7
- package/dist/tools/read/guides.js +4 -4
- package/dist/tools/read/points.js +4 -4
- package/dist/tools/read/pools.js +8 -8
- package/dist/tools/read/strategy.js +12 -12
- package/dist/tools/read/wallet.js +15 -15
- package/dist/tools/write/account/add-liquidity.js +9 -9
- package/dist/tools/write/account/aero-upgrade.js +124 -0
- package/dist/tools/write/account/borrow.js +5 -5
- package/dist/tools/write/account/close.js +8 -8
- package/dist/tools/write/account/create.js +3 -3
- package/dist/tools/write/account/deleverage.js +4 -4
- package/dist/tools/write/account/deposit.js +4 -4
- package/dist/tools/write/account/format-response.js +1 -1
- package/dist/tools/write/account/remove-liquidity.js +6 -6
- package/dist/tools/write/account/repay.js +4 -4
- package/dist/tools/write/account/stake.js +5 -5
- package/dist/tools/write/account/swap.js +4 -4
- package/dist/tools/write/account/withdraw.js +5 -5
- package/dist/tools/write/asset-managers/automations.js +14 -14
- package/dist/tools/write/asset-managers/intents.js +10 -7
- package/dist/tools/write/pool/deposit.js +5 -5
- package/dist/tools/write/pool/redeem.js +4 -4
- package/dist/tools/write/wallet/approve.js +4 -4
- package/dist/tools/write/wallet/upgrade-velo.js +76 -0
- package/dist/utils/analytics.js +68 -0
- package/dist/utils/http-config.js +4 -4
- package/llms-full.txt +83 -46
- package/llms.txt +47 -44
- package/package.json +8 -4
- package/server.json +4 -4
- package/skills/clamm-liquidity/SKILL.md +100 -82
- package/skills/clamm-liquidity/automation.md +14 -14
- package/skills/clamm-liquidity/selection.md +13 -13
- package/skills/clamm-liquidity/strategies.md +135 -53
- package/skills/openclaw/SKILL.md +3 -3
- package/skills/openclaw/arcadia.sh +24 -45
- package/skills/openclaw/contracts.md +11 -10
- package/dist/utils/tool-naming.js +0 -91
|
@@ -58,7 +58,7 @@ const ClaimRewardsIntent = z.object({
|
|
|
58
58
|
.describe("Subset of this intent's claimed tokens to swap to buy_token; the rest are claimed as-earned. Must be a subset of `tokens`. " +
|
|
59
59
|
"Omit to defer to mode (convert_to converts all claimed tokens, as_earned converts none). Use this for a partial convert, e.g. tokens: ['token0','reward'] with convert_tokens: ['reward'] swaps only the reward and claims token0 as-is."),
|
|
60
60
|
})
|
|
61
|
-
.
|
|
61
|
+
.prefault({}),
|
|
62
62
|
});
|
|
63
63
|
const AddToLpIntent = z.object({
|
|
64
64
|
kind: z.literal("add_to_lp"),
|
|
@@ -81,7 +81,7 @@ const ClaimMerklIntent = z.object({
|
|
|
81
81
|
.optional()
|
|
82
82
|
.describe("Explicit recipient address. Overrides destination when set."),
|
|
83
83
|
})
|
|
84
|
-
.
|
|
84
|
+
.prefault({}),
|
|
85
85
|
});
|
|
86
86
|
const OutOfRangeStrategy = z.object({
|
|
87
87
|
kind: z.literal("out_of_range"),
|
|
@@ -143,18 +143,18 @@ const RebalanceIntent = z.object({
|
|
|
143
143
|
position_id: POSITION_ID,
|
|
144
144
|
strategy: z
|
|
145
145
|
.discriminatedUnion("kind", [OutOfRangeStrategy, POLStrategy, TakeProfitStrategy])
|
|
146
|
-
.
|
|
146
|
+
.prefault({ kind: "out_of_range" })
|
|
147
147
|
.describe("out_of_range repositions when price leaves the range; take_profit runs on the dedicated profit-taker contract; protocol_owned_liquidity is the POL strategy."),
|
|
148
148
|
max_tolerance: z
|
|
149
149
|
.number()
|
|
150
|
-
.
|
|
150
|
+
.multipleOf(1)
|
|
151
151
|
.min(0)
|
|
152
152
|
.max(10 ** 18)
|
|
153
153
|
.optional()
|
|
154
154
|
.describe("Max price deviation (MEV/slippage cap), 1e18-scaled: 1e18 = 100%, so 5000000000000000 = 0.5% (the default) and 50000000000000000 = 5%. Omit for the pool's default. AAA pools are floored at 5%."),
|
|
155
155
|
min_liquidity_ratio: z
|
|
156
156
|
.number()
|
|
157
|
-
.
|
|
157
|
+
.multipleOf(1)
|
|
158
158
|
.min(0)
|
|
159
159
|
.max(10 ** 18)
|
|
160
160
|
.optional()
|
|
@@ -182,6 +182,8 @@ const DEX_PROTOCOL_TO_CONTEXT = {
|
|
|
182
182
|
staked_slipstream_v3: { protocol: "slipstream_v3", is_staked: true },
|
|
183
183
|
uniV3: { protocol: "uniswap_v3", is_staked: false },
|
|
184
184
|
uniV4: { protocol: "uniswap_v4", is_staked: false },
|
|
185
|
+
metadexcl_v1: { protocol: "metadexcl_v1", is_staked: false },
|
|
186
|
+
staked_metadexcl_v1: { protocol: "metadexcl_v1", is_staked: true },
|
|
185
187
|
};
|
|
186
188
|
// The canonical names plus the dex_protocol spellings, deduped: slipstream_v2 and
|
|
187
189
|
// slipstream_v3 are spelled the same in both vocabularies and must not appear twice
|
|
@@ -193,6 +195,7 @@ const PROTOCOL_VALUES = [
|
|
|
193
195
|
"slipstream_v3",
|
|
194
196
|
"uniswap_v3",
|
|
195
197
|
"uniswap_v4",
|
|
198
|
+
"metadexcl_v1",
|
|
196
199
|
...Object.keys(DEX_PROTOCOL_TO_CONTEXT),
|
|
197
200
|
]),
|
|
198
201
|
];
|
|
@@ -203,11 +206,11 @@ export const POSITION_CONTEXT_SCHEMA = {
|
|
|
203
206
|
.number()
|
|
204
207
|
.int()
|
|
205
208
|
.optional()
|
|
206
|
-
.describe("LP position (NFT) id, as listed in assets[] by
|
|
209
|
+
.describe("LP position (NFT) id, as listed in assets[] by read_account_info. Supply this and the backend fetches protocol, staked flag, tokens and reward tokens for you. Strongly preferred over passing the position fields by hand."),
|
|
207
210
|
protocol: z
|
|
208
211
|
.enum(PROTOCOL_VALUES)
|
|
209
212
|
.optional()
|
|
210
|
-
.describe("Position's DEX protocol. Only needed when position_id is omitted. Accepts the dex_protocol values the read tools return (slipstream, staked_slipstream_v3, uniV3, ...), which imply is_staked, as well as the canonical slipstream_v1 / uniswap_v3 spellings."),
|
|
213
|
+
.describe("Position's DEX protocol. Only needed when position_id is omitted. Accepts the dex_protocol values the read tools return (slipstream, staked_slipstream_v3, uniV3, metadexcl_v1, staked_metadexcl_v1, ...), which imply is_staked, as well as the canonical slipstream_v1 / uniswap_v3 spellings. metadexcl_v1 is Aero CL; staked_metadexcl_v1 covers both the staked module and the wrapper."),
|
|
211
214
|
is_staked: z
|
|
212
215
|
.boolean()
|
|
213
216
|
.optional()
|
|
@@ -6,7 +6,7 @@ import { appendDataSuffix } from "../../../utils/attribution.js";
|
|
|
6
6
|
import { validateAddress } from "../../../utils/validation.js";
|
|
7
7
|
import { SimpleTransactionOutput } from "../../output-schemas.js";
|
|
8
8
|
export function registerPoolDepositTool(server, _chains) {
|
|
9
|
-
server.registerTool("
|
|
9
|
+
server.registerTool("write_pool_deposit", {
|
|
10
10
|
annotations: {
|
|
11
11
|
title: "Build Pool Deposit Transaction",
|
|
12
12
|
readOnlyHint: false,
|
|
@@ -15,11 +15,11 @@ export function registerPoolDepositTool(server, _chains) {
|
|
|
15
15
|
openWorldHint: false,
|
|
16
16
|
},
|
|
17
17
|
outputSchema: SimpleTransactionOutput,
|
|
18
|
-
description: "Build an unsigned deposit transaction into an Arcadia lending tranche (ERC-4626). Lenders deposit the pool's underlying asset (USDC/WETH/cbBTC) and receive tranche shares that accrue interest from borrowers. Requires prior ERC-20 approval to the tranche (see
|
|
19
|
-
inputSchema: {
|
|
18
|
+
description: "Build an unsigned deposit transaction into an Arcadia lending tranche (ERC-4626). Lenders deposit the pool's underlying asset (USDC/WETH/cbBTC) and receive tranche shares that accrue interest from borrowers. Requires prior ERC-20 approval to the tranche (see write_wallet_approve). To check current lender yield, call read_pool_list or read_pool_info.",
|
|
19
|
+
inputSchema: z.object({
|
|
20
20
|
tranche_address: z
|
|
21
21
|
.string()
|
|
22
|
-
.describe("Tranche contract address (ERC-4626 vault). Get this from
|
|
22
|
+
.describe("Tranche contract address (ERC-4626 vault). Get this from read_pool_list: each pool's `tranches[0].address`."),
|
|
23
23
|
assets: z
|
|
24
24
|
.string()
|
|
25
25
|
.describe("Amount of underlying asset to deposit, in raw units (e.g. '1000000' = 1 USDC since USDC has 6 decimals)."),
|
|
@@ -27,7 +27,7 @@ export function registerPoolDepositTool(server, _chains) {
|
|
|
27
27
|
.string()
|
|
28
28
|
.describe("Address that receives the minted tranche shares. Usually the depositor's own wallet."),
|
|
29
29
|
chain_id: z.number().default(8453).describe(CHAIN_ID_DESCRIPTION),
|
|
30
|
-
},
|
|
30
|
+
}),
|
|
31
31
|
}, async (params) => {
|
|
32
32
|
try {
|
|
33
33
|
const validTranche = validateAddress(params.tranche_address, "tranche_address");
|
|
@@ -6,7 +6,7 @@ import { appendDataSuffix } from "../../../utils/attribution.js";
|
|
|
6
6
|
import { validateAddress } from "../../../utils/validation.js";
|
|
7
7
|
import { SimpleTransactionOutput } from "../../output-schemas.js";
|
|
8
8
|
export function registerPoolRedeemTool(server, _chains) {
|
|
9
|
-
server.registerTool("
|
|
9
|
+
server.registerTool("write_pool_redeem", {
|
|
10
10
|
annotations: {
|
|
11
11
|
title: "Build Pool Redeem Transaction",
|
|
12
12
|
readOnlyHint: false,
|
|
@@ -16,10 +16,10 @@ export function registerPoolRedeemTool(server, _chains) {
|
|
|
16
16
|
},
|
|
17
17
|
outputSchema: SimpleTransactionOutput,
|
|
18
18
|
description: "Build an unsigned redeem transaction to withdraw from an Arcadia lending tranche (ERC-4626). Burns tranche shares and returns the corresponding amount of underlying asset, including accrued interest. The owner must be the shares holder; receiver is where the underlying asset is sent.",
|
|
19
|
-
inputSchema: {
|
|
19
|
+
inputSchema: z.object({
|
|
20
20
|
tranche_address: z
|
|
21
21
|
.string()
|
|
22
|
-
.describe("Tranche contract address (ERC-4626 vault). Get this from
|
|
22
|
+
.describe("Tranche contract address (ERC-4626 vault). Get this from read_pool_list: each pool's `tranches[0].address`."),
|
|
23
23
|
shares: z
|
|
24
24
|
.string()
|
|
25
25
|
.describe("Amount of tranche shares to burn, in raw units. To redeem everything, use the owner's full share balance."),
|
|
@@ -30,7 +30,7 @@ export function registerPoolRedeemTool(server, _chains) {
|
|
|
30
30
|
.string()
|
|
31
31
|
.describe("Address that owns the tranche shares being burned. Normally the signer's own wallet."),
|
|
32
32
|
chain_id: z.number().default(8453).describe(CHAIN_ID_DESCRIPTION),
|
|
33
|
-
},
|
|
33
|
+
}),
|
|
34
34
|
}, async (params) => {
|
|
35
35
|
try {
|
|
36
36
|
const validTranche = validateAddress(params.tranche_address, "tranche_address");
|
|
@@ -7,7 +7,7 @@ import { validateAddress } from "../../../utils/validation.js";
|
|
|
7
7
|
import { SimpleTransactionOutput } from "../../output-schemas.js";
|
|
8
8
|
const MAX_UINT256 = 2n ** 256n - 1n;
|
|
9
9
|
export function registerApproveTool(server, _chains) {
|
|
10
|
-
server.registerTool("
|
|
10
|
+
server.registerTool("write_wallet_approve", {
|
|
11
11
|
annotations: {
|
|
12
12
|
title: "Build Approve Transaction",
|
|
13
13
|
readOnlyHint: false,
|
|
@@ -16,8 +16,8 @@ export function registerApproveTool(server, _chains) {
|
|
|
16
16
|
openWorldHint: false,
|
|
17
17
|
},
|
|
18
18
|
outputSchema: SimpleTransactionOutput,
|
|
19
|
-
description: "Build an unsigned approval transaction. For ERC20 tokens: generates approve(spender, amount). For ERC721/ERC1155 NFTs (e.g. LP positions): generates setApprovalForAll(operator, true). Required before
|
|
20
|
-
inputSchema: {
|
|
19
|
+
description: "Build an unsigned approval transaction. For ERC20 tokens: generates approve(spender, amount). For ERC721/ERC1155 NFTs (e.g. LP positions): generates setApprovalForAll(operator, true). Required before write_account_deposit or write_account_add_liquidity (when depositing from wallet). Tip: call read_wallet_allowances first to check if approval already exists: skip this if the current allowance is sufficient.",
|
|
20
|
+
inputSchema: z.object({
|
|
21
21
|
token_address: z.string().describe("Token contract address to approve"),
|
|
22
22
|
spender_address: z
|
|
23
23
|
.string()
|
|
@@ -31,7 +31,7 @@ export function registerApproveTool(server, _chains) {
|
|
|
31
31
|
.default("max_uint256")
|
|
32
32
|
.describe("ERC20 only: amount in raw units, or 'max_uint256' for unlimited. Ignored for NFTs."),
|
|
33
33
|
chain_id: z.number().default(8453).describe(CHAIN_ID_DESCRIPTION),
|
|
34
|
-
},
|
|
34
|
+
}),
|
|
35
35
|
}, async (params) => {
|
|
36
36
|
try {
|
|
37
37
|
const validToken = validateAddress(params.token_address, "token_address");
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { appendDataSuffix } from "../../../utils/attribution.js";
|
|
3
|
+
import { parseWeiDecimalString, validateAddress } from "../../../utils/validation.js";
|
|
4
|
+
import { aeroErrorResult } from "../../aero.js";
|
|
5
|
+
import { VeloUpgradeOutput } from "../../output-schemas.js";
|
|
6
|
+
const OPTIMISM = 10;
|
|
7
|
+
export function registerUpgradeVeloTool(server, api) {
|
|
8
|
+
server.registerTool("write_wallet_upgrade_velo", {
|
|
9
|
+
annotations: {
|
|
10
|
+
title: "Build VELO Upgrade Transactions",
|
|
11
|
+
readOnlyHint: false,
|
|
12
|
+
destructiveHint: false,
|
|
13
|
+
idempotentHint: true,
|
|
14
|
+
openWorldHint: true,
|
|
15
|
+
},
|
|
16
|
+
outputSchema: VeloUpgradeOutput,
|
|
17
|
+
description: "Upgrade VELO held in a wallet on Optimism to the new AERO on Base: ordered unsigned wallet transactions from owner_address, an approve when the allowance is short, then depositLiquid on the Velodrome migration with the Hyperlane fee as value. 0.044 new AERO per VELO arrives at the same address on Base once the message lands. " +
|
|
18
|
+
"VELO inside an Arcadia account must be withdrawn to the wallet first (write_account_withdraw). VELO stays usable, so this is optional. Optimism (chain_id 10) only. 'upgrade unavailable' names the contract's reason: not_open (with the opening time), paused, budget_exhausted, recipient_not_deployed (a contract wallet with no code on Base).",
|
|
19
|
+
inputSchema: z.object({
|
|
20
|
+
owner_address: z
|
|
21
|
+
.string()
|
|
22
|
+
.describe("Wallet holding the VELO on Optimism; receives the AERO on Base"),
|
|
23
|
+
amount: z
|
|
24
|
+
.string()
|
|
25
|
+
.optional()
|
|
26
|
+
.describe("Raw units (18 decimals). Omit for the wallet's full VELO balance."),
|
|
27
|
+
chain_id: z.number().default(OPTIMISM).describe("Chain ID: 10 (Optimism)"),
|
|
28
|
+
}),
|
|
29
|
+
}, async ({ owner_address, amount, chain_id }) => {
|
|
30
|
+
try {
|
|
31
|
+
if (chain_id !== OPTIMISM) {
|
|
32
|
+
throw new Error(`The VELO upgrade runs on Optimism (chain_id 10), not on chain ${chain_id}.`);
|
|
33
|
+
}
|
|
34
|
+
const owner = validateAddress(owner_address, "owner_address");
|
|
35
|
+
if (amount !== undefined)
|
|
36
|
+
parseWeiDecimalString(amount, "amount");
|
|
37
|
+
const result = await api.getUpgradeVeloCalldata({
|
|
38
|
+
chain_id: OPTIMISM,
|
|
39
|
+
owner_address: owner,
|
|
40
|
+
amount,
|
|
41
|
+
});
|
|
42
|
+
if (BigInt(result.wallet_balance) < BigInt(result.amount_in)) {
|
|
43
|
+
throw new Error(`${owner} holds ${result.wallet_balance} VELO on Optimism, less than the ${result.amount_in} requested; the deposit would revert.`);
|
|
44
|
+
}
|
|
45
|
+
const last = result.calls.length - 1;
|
|
46
|
+
const response = {
|
|
47
|
+
description: `Upgrade ${result.amount_in} VELO on Optimism to ${result.expected_amount_out} new AERO, paid to ${result.recipient} on Base`,
|
|
48
|
+
transactions: result.calls.map((call, i) => ({
|
|
49
|
+
description: i === last
|
|
50
|
+
? `Deposit ${result.amount_in} VELO into the Velodrome migration (Hyperlane fee ${call.value} wei)`
|
|
51
|
+
: `Approve the Velodrome migration ${result.migration} to spend ${result.amount_in} VELO`,
|
|
52
|
+
transaction: {
|
|
53
|
+
to: call.to,
|
|
54
|
+
data: appendDataSuffix(call.data),
|
|
55
|
+
value: call.value,
|
|
56
|
+
chainId: result.chain_id,
|
|
57
|
+
},
|
|
58
|
+
})),
|
|
59
|
+
destination_chain_id: result.destination_chain_id,
|
|
60
|
+
recipient: result.recipient,
|
|
61
|
+
old_token: result.old_token,
|
|
62
|
+
new_token: result.new_token,
|
|
63
|
+
amount_in: result.amount_in,
|
|
64
|
+
expected_amount_out: result.expected_amount_out,
|
|
65
|
+
fee_wei: result.fee_wei,
|
|
66
|
+
};
|
|
67
|
+
return {
|
|
68
|
+
content: [{ type: "text", text: JSON.stringify(response, null, 2) }],
|
|
69
|
+
structuredContent: response,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
catch (err) {
|
|
73
|
+
return aeroErrorResult(err);
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { randomUUID } from "crypto";
|
|
2
|
+
import { PostHog } from "posthog-node";
|
|
3
|
+
const processId = randomUUID();
|
|
4
|
+
// Only the hosted HTTP server reports, and only with POSTHOG_KEY set. A local
|
|
5
|
+
// stdio install never does, even when its environment sets POSTHOG_KEY for
|
|
6
|
+
// another app. Read at call time: index.ts loads env files after static imports run.
|
|
7
|
+
export function createAnalytics(transport) {
|
|
8
|
+
if (transport !== "http")
|
|
9
|
+
return null;
|
|
10
|
+
const key = process.env.POSTHOG_KEY?.trim();
|
|
11
|
+
if (!key)
|
|
12
|
+
return null;
|
|
13
|
+
// flushAt 1: a process can exit at any time, so don't hold a batch.
|
|
14
|
+
return new PostHog(key, {
|
|
15
|
+
// An empty POSTHOG_HOST would make posthog-node fall back to the US host.
|
|
16
|
+
host: process.env.POSTHOG_HOST?.trim() || "https://eu.i.posthog.com",
|
|
17
|
+
flushAt: 1,
|
|
18
|
+
flushInterval: 0,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
// Captures one `mcp_tool_called` event per tool invocation: name, arguments,
|
|
22
|
+
// outcome and the calling client, keyed by the per-process id.
|
|
23
|
+
export function withAnalytics(target, mcp, analytics, meta) {
|
|
24
|
+
return new Proxy(target, {
|
|
25
|
+
get(t, prop, receiver) {
|
|
26
|
+
if (prop !== "registerTool")
|
|
27
|
+
return Reflect.get(t, prop, receiver);
|
|
28
|
+
return (name, config, cb) => {
|
|
29
|
+
const hasInput = config.inputSchema !== undefined;
|
|
30
|
+
const wrappedCb = async (...args) => {
|
|
31
|
+
const input = hasInput ? args[0] : undefined;
|
|
32
|
+
const extra = (hasInput ? args[1] : args[0]);
|
|
33
|
+
const started = Date.now();
|
|
34
|
+
let result;
|
|
35
|
+
let thrown;
|
|
36
|
+
try {
|
|
37
|
+
result = (await cb(...args));
|
|
38
|
+
return result;
|
|
39
|
+
}
|
|
40
|
+
catch (err) {
|
|
41
|
+
thrown = err;
|
|
42
|
+
throw err;
|
|
43
|
+
}
|
|
44
|
+
finally {
|
|
45
|
+
const client = mcp.server.getClientVersion();
|
|
46
|
+
analytics.capture({
|
|
47
|
+
distinctId: extra?.sessionId ?? processId,
|
|
48
|
+
event: "mcp_tool_called",
|
|
49
|
+
properties: {
|
|
50
|
+
tool: name,
|
|
51
|
+
args: input,
|
|
52
|
+
is_error: thrown !== undefined || result?.isError === true,
|
|
53
|
+
error: thrown instanceof Error ? thrown.message : undefined,
|
|
54
|
+
duration_ms: Date.now() - started,
|
|
55
|
+
transport: meta.transport,
|
|
56
|
+
client_name: client?.name,
|
|
57
|
+
client_version: client?.version,
|
|
58
|
+
server_version: meta.serverVersion,
|
|
59
|
+
$process_person_profile: false,
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
return t.registerTool(name, config, wrappedCb);
|
|
65
|
+
};
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
}
|
|
@@ -6,12 +6,12 @@ export function parseListenPort(raw) {
|
|
|
6
6
|
}
|
|
7
7
|
return n;
|
|
8
8
|
}
|
|
9
|
-
/** Max requests per minute from RATE_LIMIT_RPM. Warns and falls back to
|
|
9
|
+
/** Max requests per minute per client IP from RATE_LIMIT_RPM. Warns and falls back to 600 on invalid input. */
|
|
10
10
|
export function parseRateLimitRpm(raw) {
|
|
11
|
-
const n = parseInt(raw ?? "
|
|
11
|
+
const n = parseInt(raw ?? "600", 10);
|
|
12
12
|
if (!Number.isFinite(n) || n < 1) {
|
|
13
|
-
console.warn(`Invalid RATE_LIMIT_RPM "${raw ?? ""}", using default
|
|
14
|
-
return
|
|
13
|
+
console.warn(`Invalid RATE_LIMIT_RPM "${raw ?? ""}", using default 600`);
|
|
14
|
+
return 600;
|
|
15
15
|
}
|
|
16
16
|
return Math.min(n, 1_000_000);
|
|
17
17
|
}
|