felix-mcp 2.0.123 → 2.0.129
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 +26 -3
- package/dist/arc-hl-return-ports.js +15 -2
- package/dist/arc-hl-return.js +4 -2
- package/dist/arc-home.js +3 -10
- package/dist/arc-hypercore-funding.js +1076 -0
- package/dist/arc-hypercore-return.js +826 -0
- package/dist/arc-pm-return.js +28 -3
- package/dist/arc-safe-invalidation-hints.js +209 -0
- package/dist/arc-safe-invalidation.js +672 -0
- package/dist/arc-venue-app-policy.js +30 -0
- package/dist/funding.js +192 -25
- package/dist/getting-started-guide.js +12 -2
- package/dist/http-server.js +25 -8
- package/dist/index.js +821 -202
- package/dist/key-backup.js +15 -4
- package/dist/polymarket.js +5 -3
- package/dist/public-venue.js +35 -0
- package/dist/rpc-endpoints.js +133 -0
- package/dist/safe-migration.js +7 -3
- package/dist/safe-onboarding.js +58 -49
- package/dist/safe-policy.js +39 -28
- package/package.json +14 -2
- package/server.json +2 -2
package/dist/key-backup.js
CHANGED
|
@@ -281,6 +281,14 @@ export function parseCliArgs(argv) {
|
|
|
281
281
|
parsed.acceptTerms = true;
|
|
282
282
|
continue;
|
|
283
283
|
}
|
|
284
|
+
if (item === "--confirm-on-mac") {
|
|
285
|
+
// ONBOARD_CONSENT_20261117: the owner's answer was relayed by an AI agent, so a new owner key is created
|
|
286
|
+
// only after the owner clicks the native macOS confirmation as well.
|
|
287
|
+
if (parsed.confirmOnMac)
|
|
288
|
+
throw new Error("--confirm-on-mac may be provided only once.");
|
|
289
|
+
parsed.confirmOnMac = true;
|
|
290
|
+
continue;
|
|
291
|
+
}
|
|
284
292
|
throw new Error(`Unknown argument: ${item}`);
|
|
285
293
|
}
|
|
286
294
|
if (["backup", "onboard"].includes(parsed.command) && parsed.input) {
|
|
@@ -295,6 +303,9 @@ export function parseCliArgs(argv) {
|
|
|
295
303
|
if (parsed.command !== "onboard" && parsed.client) {
|
|
296
304
|
throw new Error("--client is accepted only by onboard.");
|
|
297
305
|
}
|
|
306
|
+
if (parsed.command !== "onboard" && parsed.confirmOnMac) {
|
|
307
|
+
throw new Error("--confirm-on-mac is accepted only by onboard.");
|
|
308
|
+
}
|
|
298
309
|
if (parsed.command !== "onboard" && parsed.acceptTerms) {
|
|
299
310
|
throw new Error("--accept-terms is accepted only by onboard.");
|
|
300
311
|
}
|
|
@@ -1077,9 +1088,9 @@ async function registerCommand(allowExisting = false, agentManaged = false) {
|
|
|
1077
1088
|
console.log(`API key stored in Keychain (prefix ${apiKey.slice(0, 8)}). The key itself was not printed.`);
|
|
1078
1089
|
console.log("Run guided onboarding to create and authenticate the encrypted recovery file automatically before funding.");
|
|
1079
1090
|
}
|
|
1080
|
-
async function onboardCommand(client = "claude", output) {
|
|
1091
|
+
async function onboardCommand(client = "claude", output, confirmOnMac = false) {
|
|
1081
1092
|
requireNativeMacSession();
|
|
1082
|
-
await registerCommand(true,
|
|
1093
|
+
await registerCommand(true, !confirmOnMac);
|
|
1083
1094
|
const ownerKey = readKeychainPassword(OWNER_KEYCHAIN_SERVICE);
|
|
1084
1095
|
const apiKey = readKeychainPassword(API_KEYCHAIN_SERVICE);
|
|
1085
1096
|
if (!ownerKey || !PRIVATE_KEY_RE.test(ownerKey) || !apiKey || !API_KEY_RE.test(apiKey)) {
|
|
@@ -1185,7 +1196,7 @@ function printHelp() {
|
|
|
1185
1196
|
console.log(`Felix local custody setup and recovery
|
|
1186
1197
|
|
|
1187
1198
|
Usage:
|
|
1188
|
-
felix-keys onboard --accept-terms [--client claude|none] [--output <file>]
|
|
1199
|
+
felix-keys onboard --accept-terms [--client claude|none] [--output <file>] [--confirm-on-mac]
|
|
1189
1200
|
felix-keys setup
|
|
1190
1201
|
felix-keys register
|
|
1191
1202
|
felix-keys set-api-key
|
|
@@ -1213,7 +1224,7 @@ async function main() {
|
|
|
1213
1224
|
if (args.command === "help")
|
|
1214
1225
|
printHelp();
|
|
1215
1226
|
else if (args.command === "onboard")
|
|
1216
|
-
await onboardCommand(args.client, args.output);
|
|
1227
|
+
await onboardCommand(args.client, args.output, args.confirmOnMac === true);
|
|
1217
1228
|
else if (args.command === "setup")
|
|
1218
1229
|
setupCommand();
|
|
1219
1230
|
else if (args.command === "set-api-key")
|
package/dist/polymarket.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { lazyRpcTransport } from "./rpc-endpoints.js";
|
|
1
2
|
import { redactOutput } from "./redact-output.js";
|
|
2
|
-
import { createWalletClient, decodeFunctionData, getAddress, hashTypedData,
|
|
3
|
+
import { createWalletClient, decodeFunctionData, getAddress, hashTypedData, parseAbi } from "viem";
|
|
3
4
|
import { privateKeyToAccount } from "viem/accounts";
|
|
4
5
|
import { polygon } from "viem/chains";
|
|
5
6
|
import { ApiError, AssetType, Chain, ClobClient, createL2Headers, getContractConfig, isV2Order, orderToJsonV1, orderToJsonV2, OrderType, Side, SignatureTypeV2, } from "./vendor/polymarket-clob-v2/index.js";
|
|
@@ -10,7 +11,8 @@ const BUILDER_CODE_RE = /^0x[0-9a-fA-F]{64}$/;
|
|
|
10
11
|
const UINT_RE = /^\d+$/;
|
|
11
12
|
const CLOB_HOST = "https://clob.polymarket.com";
|
|
12
13
|
const GAMMA_HOST = "https://gamma-api.polymarket.com";
|
|
13
|
-
|
|
14
|
+
// NO_PUBLIC_RPC_20261115: the local wallet only signs; an RPC request (never expected)
|
|
15
|
+
// would need the user's own FELIX_POLYGON_RPC_URL and never falls back to a public RPC.
|
|
14
16
|
const PUSD = getAddress("0xC011a7E12a19f7B1f670d46F03B03f3342E82DFB");
|
|
15
17
|
const USDC_E = getAddress("0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174");
|
|
16
18
|
const OFFRAMP = getAddress("0x2957922Eb93258b93368531d39fAcCA3B4dC5854");
|
|
@@ -187,7 +189,7 @@ function localWallet(overrideKey) {
|
|
|
187
189
|
? overrideKey
|
|
188
190
|
: privateKey();
|
|
189
191
|
const account = privateKeyToAccount(key);
|
|
190
|
-
const wallet = createWalletClient({ account, chain: polygon, transport:
|
|
192
|
+
const wallet = createWalletClient({ account, chain: polygon, transport: lazyRpcTransport("polygon") });
|
|
191
193
|
return { account, wallet };
|
|
192
194
|
}
|
|
193
195
|
export function localOwnerAddress() {
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// The public API never shows a venue name (engine services/public_api/app.py
|
|
2
|
+
// _scrub_venue runs on every /v1/ JSON answer): a record's "venue" key arrives
|
|
3
|
+
// as "market" with the venue's asset-class alias, and a bare string equal to a
|
|
4
|
+
// venue name arrives as that alias. Signed protocol payloads (typed_data,
|
|
5
|
+
// action, relay_order, ...) pass through untouched, so hashes and signatures
|
|
6
|
+
// are unaffected. A client check on a venue NAME therefore accepts exactly the
|
|
7
|
+
// name or its public alias and nothing else; the binding facts stay the chain
|
|
8
|
+
// ids, tokens, addresses and signed payloads checked next to it.
|
|
9
|
+
// Found by the 2.0.221 canaries (HyperCore return "crypto", A6-HL).
|
|
10
|
+
export const PUBLIC_VENUE_ALIAS = {
|
|
11
|
+
hyperliquid: "crypto",
|
|
12
|
+
hyperliquid_spot: "spot",
|
|
13
|
+
polymarket: "prediction_market",
|
|
14
|
+
derive: "options",
|
|
15
|
+
};
|
|
16
|
+
/** A string field naming `venue`, in either the engine or the public spelling. */
|
|
17
|
+
export function namesVenue(value, venue) {
|
|
18
|
+
return value === venue || value === PUBLIC_VENUE_ALIAS[venue];
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* A record scoped to `venue`: the engine's `venue` key, the public `market`
|
|
22
|
+
* key (the scrub renames it), or both when they agree. Neither, another venue,
|
|
23
|
+
* or another market fails closed.
|
|
24
|
+
*/
|
|
25
|
+
export function recordVenueIs(record, venue) {
|
|
26
|
+
const hasVenue = record.venue !== undefined;
|
|
27
|
+
const hasMarket = record.market !== undefined;
|
|
28
|
+
if (!hasVenue && !hasMarket)
|
|
29
|
+
return false;
|
|
30
|
+
if (hasVenue && record.venue !== venue)
|
|
31
|
+
return false;
|
|
32
|
+
if (hasMarket && record.market !== PUBLIC_VENUE_ALIAS[venue])
|
|
33
|
+
return false;
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
// Client-side chain RPC resolution. NO_PUBLIC_RPC_2026_09_25.
|
|
2
|
+
//
|
|
3
|
+
// Operator rule: account-sensitive calls (owner-wallet broadcasts, owner/Safe
|
|
4
|
+
// address reads) never go to a public RPC. Every chain RPC this client uses
|
|
5
|
+
// comes from FELIX_<CHAIN>_RPC_URL; there is no public default. Mirrors
|
|
6
|
+
// arc-home.ts broadcastOwnerCall, which already refuses without a configured
|
|
7
|
+
// URL ("this client never uses a public RPC").
|
|
8
|
+
//
|
|
9
|
+
// Everything here is LAZY: resolution happens at the call site that is about
|
|
10
|
+
// to talk to the chain, never at import time, so importing a module that uses
|
|
11
|
+
// an RPC never throws and flows that do not touch the chain (the Felix funding
|
|
12
|
+
// relay path, local EIP-712 signing) are unaffected by an unset variable.
|
|
13
|
+
import { custom, http } from "viem";
|
|
14
|
+
// Hosts (and all their subdomains) that are public/shared RPC providers. A
|
|
15
|
+
// FELIX_<CHAIN>_RPC_URL pointing at one of these is refused like an unset one.
|
|
16
|
+
export const PUBLIC_RPC_HOST_DENYLIST = [
|
|
17
|
+
"publicnode.com",
|
|
18
|
+
"drpc.org",
|
|
19
|
+
"llamarpc.com",
|
|
20
|
+
"ankr.com",
|
|
21
|
+
"cloudflare-eth.com",
|
|
22
|
+
"arb1.arbitrum.io",
|
|
23
|
+
"mainnet.base.org",
|
|
24
|
+
"polygon-rpc.com",
|
|
25
|
+
"rpc.derive.xyz",
|
|
26
|
+
"rpc.lyra.finance",
|
|
27
|
+
"1rpc.io",
|
|
28
|
+
"blastapi.io",
|
|
29
|
+
];
|
|
30
|
+
const CHAIN_NAME_RE = /^[a-z][a-z0-9_]{0,31}$/;
|
|
31
|
+
function rpcError(code, message, envName = null) {
|
|
32
|
+
const error = new Error(message);
|
|
33
|
+
Object.defineProperty(error, "name", { value: "RpcError", enumerable: false, configurable: true, writable: true });
|
|
34
|
+
error.code = code;
|
|
35
|
+
error.moneyMoved = false;
|
|
36
|
+
error.notStarted = true;
|
|
37
|
+
error.retryable = false;
|
|
38
|
+
error.envName = envName;
|
|
39
|
+
return error;
|
|
40
|
+
}
|
|
41
|
+
const RPC_ERROR_CODES = new Set(["rpc_unconfigured", "rpc_public_refused", "rpc_invalid"]);
|
|
42
|
+
/** True for a resolution refusal from this module (duck-typed; survives bundling). */
|
|
43
|
+
export function isRpcConfigError(error) {
|
|
44
|
+
return error instanceof Error
|
|
45
|
+
&& error.name === "RpcError"
|
|
46
|
+
&& typeof error.code === "string"
|
|
47
|
+
&& RPC_ERROR_CODES.has(error.code)
|
|
48
|
+
&& error.notStarted === true
|
|
49
|
+
&& error.moneyMoved === false;
|
|
50
|
+
}
|
|
51
|
+
// An MCP host that has no value for an optional bundle setting may pass the
|
|
52
|
+
// literal "${user_config.<key>}" template through. Treat that as unset so the
|
|
53
|
+
// refusal says rpc_unconfigured, not rpc_invalid.
|
|
54
|
+
const UNSUBSTITUTED_TEMPLATE_RE = /^\$\{\s*user_config\.[A-Za-z0-9_]+\s*\}$/;
|
|
55
|
+
export function rpcEnvName(chain) {
|
|
56
|
+
const name = chain.trim().toLowerCase();
|
|
57
|
+
if (!CHAIN_NAME_RE.test(name))
|
|
58
|
+
throw rpcError("rpc_invalid", "Unsupported chain name for an RPC endpoint.");
|
|
59
|
+
return `FELIX_${name.toUpperCase()}_RPC_URL`;
|
|
60
|
+
}
|
|
61
|
+
/** The denylist entry a host matches (exact host or any subdomain), or null. */
|
|
62
|
+
export function publicRpcHostMatch(hostname) {
|
|
63
|
+
const host = hostname.trim().toLowerCase().replace(/\.$/, "");
|
|
64
|
+
for (const entry of PUBLIC_RPC_HOST_DENYLIST) {
|
|
65
|
+
if (host === entry || host.endsWith(`.${entry}`))
|
|
66
|
+
return entry;
|
|
67
|
+
}
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Validate an already-read RPC URL for `chain`. Unset/blank refuses with the
|
|
72
|
+
* arc-home wording; a public host refuses; anything else is returned verbatim
|
|
73
|
+
* (existing behaviour when a private URL is configured).
|
|
74
|
+
*/
|
|
75
|
+
export function requirePrivateRpcUrl(chain, value) {
|
|
76
|
+
const envName = rpcEnvName(chain);
|
|
77
|
+
const label = chain.trim().toLowerCase();
|
|
78
|
+
const trimmed = typeof value === "string" ? value.trim() : "";
|
|
79
|
+
const raw = UNSUBSTITUTED_TEMPLATE_RE.test(trimmed) ? "" : trimmed;
|
|
80
|
+
if (!raw) {
|
|
81
|
+
throw rpcError("rpc_unconfigured", `Set ${envName} to your own ${label} RPC endpoint; this client never uses a public RPC.`, envName);
|
|
82
|
+
}
|
|
83
|
+
if (!/^https?:\/\//i.test(raw)) {
|
|
84
|
+
throw rpcError("rpc_invalid", `${envName} must be an http(s) URL to your own ${label} RPC endpoint.`, envName);
|
|
85
|
+
}
|
|
86
|
+
let url;
|
|
87
|
+
try {
|
|
88
|
+
url = new URL(raw);
|
|
89
|
+
}
|
|
90
|
+
catch {
|
|
91
|
+
throw rpcError("rpc_invalid", `${envName} is not a valid URL.`, envName);
|
|
92
|
+
}
|
|
93
|
+
const matched = publicRpcHostMatch(url.hostname);
|
|
94
|
+
if (matched) {
|
|
95
|
+
// Never echo the URL itself: private RPC URLs often embed an API key.
|
|
96
|
+
throw rpcError("rpc_public_refused", `${envName} points at a public RPC (${matched}). Set ${envName} to your own ${label} RPC endpoint; this client never uses a public RPC.`, envName);
|
|
97
|
+
}
|
|
98
|
+
return value;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* OWNER_RPC_HYBRID_20261115 (owner: "private if set, else app model"): the user's own
|
|
102
|
+
* FELIX_<CHAIN>_RPC_URL when set, or null when unset, so a caller can add its local
|
|
103
|
+
* chain check only when a private endpoint exists. A value that is set but public or
|
|
104
|
+
* invalid still refuses: a misconfiguration never silently downgrades.
|
|
105
|
+
*/
|
|
106
|
+
export function optionalPrivateRpc(chain, env = process.env) {
|
|
107
|
+
const value = env[rpcEnvName(chain)];
|
|
108
|
+
const trimmed = typeof value === "string" ? value.trim() : "";
|
|
109
|
+
if (!trimmed || UNSUBSTITUTED_TEMPLATE_RE.test(trimmed))
|
|
110
|
+
return null;
|
|
111
|
+
return requirePrivateRpcUrl(chain, value);
|
|
112
|
+
}
|
|
113
|
+
/** Resolve FELIX_<CHAIN>_RPC_URL at call time; throws when unset or public. */
|
|
114
|
+
export function requireRpc(chain, env = process.env) {
|
|
115
|
+
return requirePrivateRpcUrl(chain, env[rpcEnvName(chain)]);
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* A viem transport that resolves the RPC on its FIRST request, not when the
|
|
119
|
+
* client is created. For clients that exist mainly to hold a local account
|
|
120
|
+
* (EIP-712 signing never touches the RPC): creating them never throws, while
|
|
121
|
+
* any actual RPC request refuses when the variable is unset or public.
|
|
122
|
+
*/
|
|
123
|
+
export function lazyRpcTransport(chain, env = process.env) {
|
|
124
|
+
rpcEnvName(chain);
|
|
125
|
+
let inner;
|
|
126
|
+
return custom({
|
|
127
|
+
async request(args) {
|
|
128
|
+
if (!inner)
|
|
129
|
+
inner = http(requireRpc(chain, env))({}).request;
|
|
130
|
+
return inner(args);
|
|
131
|
+
},
|
|
132
|
+
}, { retryCount: 0 });
|
|
133
|
+
}
|
package/dist/safe-migration.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { bytesToHex, createPublicClient, createWalletClient, decodeFunctionData, encodeFunctionData, getAddress, hexToBytes, http, keccak256, parseAbi, } from "viem";
|
|
2
|
+
import { requireRpc } from "./rpc-endpoints.js";
|
|
2
3
|
import { privateKeyToAccount } from "viem/accounts";
|
|
3
4
|
import { polygon } from "viem/chains";
|
|
4
5
|
import { getRuntimeOwnerPrivateKey } from "./secret-state.js";
|
|
@@ -9,7 +10,9 @@ const EXPECTED_RUNTIME_BYTES = 13_956;
|
|
|
9
10
|
const ZERO_ADDRESS = getAddress("0x0000000000000000000000000000000000000000");
|
|
10
11
|
const MODULE_SENTINEL = getAddress("0x0000000000000000000000000000000000000001");
|
|
11
12
|
const FALLBACK_SLOT = "0x6c9a6c4a39284e37ed1cf53d337577d14212a4870fb976a4366c693b939918d5";
|
|
12
|
-
|
|
13
|
+
// NO_PUBLIC_RPC_20261115: the migration broadcasts from the owner wallet, so it needs the
|
|
14
|
+
// user's own private Polygon RPC (FELIX_POLYGON_RPC_URL); a public RPC is never used.
|
|
15
|
+
const RPC_URL = () => requireRpc("polygon");
|
|
13
16
|
const MAX_GAS_PRICE = 500000000000n;
|
|
14
17
|
const MAX_SAFE_EXEC_GAS = 500000n;
|
|
15
18
|
const STATE_POLL_ATTEMPTS = 15;
|
|
@@ -256,8 +259,9 @@ export async function executeSafeV3Migration(prepared, privateKey) {
|
|
|
256
259
|
|| address(disable.args[1], "disabled module").toLowerCase() !== previousModule.toLowerCase()) {
|
|
257
260
|
throw new Error("The Safe migration transaction sequence is inconsistent.");
|
|
258
261
|
}
|
|
259
|
-
const
|
|
260
|
-
const
|
|
262
|
+
const rpc = RPC_URL();
|
|
263
|
+
const client = createPublicClient({ chain: polygon, transport: http(rpc) });
|
|
264
|
+
const wallet = createWalletClient({ account, chain: polygon, transport: http(rpc) });
|
|
261
265
|
const bytecode = await client.getBytecode({ address: module });
|
|
262
266
|
if (!bytecode || normalizedRuntimeHash(bytecode).toLowerCase() !== EXPECTED_RUNTIME_HASH) {
|
|
263
267
|
throw new Error("The deployed module is not the audited Felix V3 runtime.");
|
package/dist/safe-onboarding.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { bytesToHex, createPublicClient, decodeFunctionData, getAddress, hexToBytes, http, keccak256, parseAbi, } from "viem";
|
|
2
|
+
import { optionalPrivateRpc } from "./rpc-endpoints.js";
|
|
2
3
|
import { privateKeyToAccount } from "viem/accounts";
|
|
3
4
|
import { polygon } from "viem/chains";
|
|
4
5
|
import { hkdfSync } from "node:crypto";
|
|
@@ -15,7 +16,7 @@ const OPERATORS = [
|
|
|
15
16
|
getAddress("0xE111180000d2663C0091e4f400237545B87B996B"),
|
|
16
17
|
getAddress("0xe2222d279d744050d28e00520010520000310F59"),
|
|
17
18
|
];
|
|
18
|
-
|
|
19
|
+
// NO_PUBLIC_RPC_20261115: never a public RPC (see optionalPrivateRpc).
|
|
19
20
|
const SECP256K1_N = BigInt("0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141");
|
|
20
21
|
const IMMUTABLE_RANGES = [
|
|
21
22
|
1657, 2125, 4182, 4918, 5477, 7704, 7737, 8082, 9251, 9772,
|
|
@@ -269,53 +270,58 @@ export async function signSafeOnboardingTransactions(prepared, privateKey) {
|
|
|
269
270
|
|| address(fallback.args[0], "fallback module").toLowerCase() !== module.toLowerCase()) {
|
|
270
271
|
throw new Error("Felix returned an inconsistent Safe activation sequence.");
|
|
271
272
|
}
|
|
272
|
-
const
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
address: module, abi: MODULE_ABI, functionName: "
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|| getAddress(
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
273
|
+
const privateRpc = optionalPrivateRpc("polygon");
|
|
274
|
+
// Without the user's own private RPC this local chain check is skipped: Felix's engine,
|
|
275
|
+
// which verifies the Safe with its own quorum, is trusted exactly as the app does.
|
|
276
|
+
if (privateRpc) {
|
|
277
|
+
const client = createPublicClient({ chain: polygon, transport: http(privateRpc) });
|
|
278
|
+
const bytecode = await client.getBytecode({ address: module });
|
|
279
|
+
if (!bytecode || normalizedRuntimeHash(bytecode).toLowerCase() !== EXPECTED_RUNTIME_HASH) {
|
|
280
|
+
throw new Error("The deployed Safe module is not the pinned Felix V3 runtime.");
|
|
281
|
+
}
|
|
282
|
+
const [owners, threshold, nonce, enabled, boundSafe, boundHome, boundAgent, boundCtf, boundCollateral, maxOperation, dailyLimit, lifetimeLimit, delegationExpiry, spentAmount, lifetimeSpent, approvalSpent, approvalLifetimeSpent, paused, ...allowed] = await Promise.all([
|
|
283
|
+
client.readContract({ address: safe, abi: SAFE_ABI, functionName: "getOwners" }),
|
|
284
|
+
client.readContract({ address: safe, abi: SAFE_ABI, functionName: "getThreshold" }),
|
|
285
|
+
client.readContract({ address: safe, abi: SAFE_ABI, functionName: "nonce" }),
|
|
286
|
+
client.readContract({ address: safe, abi: SAFE_ABI, functionName: "isModuleEnabled", args: [module] }),
|
|
287
|
+
client.readContract({ address: module, abi: MODULE_ABI, functionName: "safe" }),
|
|
288
|
+
client.readContract({ address: module, abi: MODULE_ABI, functionName: "home" }),
|
|
289
|
+
client.readContract({ address: module, abi: MODULE_ABI, functionName: "agent" }),
|
|
290
|
+
client.readContract({ address: module, abi: MODULE_ABI, functionName: "ctf" }),
|
|
291
|
+
client.readContract({ address: module, abi: MODULE_ABI, functionName: "collateral" }),
|
|
292
|
+
client.readContract({ address: module, abi: MODULE_ABI, functionName: "maxOperationAmount" }),
|
|
293
|
+
client.readContract({ address: module, abi: MODULE_ABI, functionName: "dailyLimit" }),
|
|
294
|
+
client.readContract({ address: module, abi: MODULE_ABI, functionName: "lifetimeLimit" }),
|
|
295
|
+
client.readContract({ address: module, abi: MODULE_ABI, functionName: "delegationExpiresAt" }),
|
|
296
|
+
client.readContract({ address: module, abi: MODULE_ABI, functionName: "spentAmount" }),
|
|
297
|
+
client.readContract({ address: module, abi: MODULE_ABI, functionName: "lifetimeSpent" }),
|
|
298
|
+
client.readContract({ address: module, abi: MODULE_ABI, functionName: "approvalSpentAmount" }),
|
|
299
|
+
client.readContract({ address: module, abi: MODULE_ABI, functionName: "approvalLifetimeSpent" }),
|
|
300
|
+
client.readContract({ address: module, abi: MODULE_ABI, functionName: "agentPaused" }),
|
|
301
|
+
...OPERATORS.map((operator) => client.readContract({
|
|
302
|
+
address: module, abi: MODULE_ABI, functionName: "allowedExchange", args: [operator],
|
|
303
|
+
})),
|
|
304
|
+
]);
|
|
305
|
+
const delegationSeconds = BigInt(Math.floor(Date.parse(text(prepared.delegation_expires_at, "delegation_expires_at")) / 1000));
|
|
306
|
+
const approvedProof = proofFields(text(prepared.proof_message, "proof_message"));
|
|
307
|
+
const preparedHome = address(approvedProof.home, "proof home");
|
|
308
|
+
const preparedAgent = address(approvedProof.agent, "proof agent");
|
|
309
|
+
if (owners.length !== 1 || getAddress(owners[0]).toLowerCase() !== owner.toLowerCase()
|
|
310
|
+
|| threshold !== 1n || nonce !== enable.nonce || enabled
|
|
311
|
+
|| getAddress(boundSafe).toLowerCase() !== safe.toLowerCase()
|
|
312
|
+
|| getAddress(boundHome).toLowerCase() !== preparedHome.toLowerCase()
|
|
313
|
+
|| getAddress(boundAgent).toLowerCase() !== preparedAgent.toLowerCase()
|
|
314
|
+
|| getAddress(boundCtf).toLowerCase() !== CTF.toLowerCase()
|
|
315
|
+
|| getAddress(boundCollateral).toLowerCase() !== COLLATERAL.toLowerCase()
|
|
316
|
+
|| maxOperation !== usdUnits(prepared.max_operation_usd, "max_operation_usd")
|
|
317
|
+
|| dailyLimit !== usdUnits(prepared.daily_limit_usd, "daily_limit_usd")
|
|
318
|
+
|| lifetimeLimit !== usdUnits(prepared.lifetime_limit_usd, "lifetime_limit_usd")
|
|
319
|
+
|| BigInt(delegationExpiry) !== delegationSeconds
|
|
320
|
+
|| delegationSeconds <= BigInt(Math.floor(Date.now() / 1000))
|
|
321
|
+
|| spentAmount !== 0n || lifetimeSpent !== 0n || approvalSpent !== 0n
|
|
322
|
+
|| approvalLifetimeSpent !== 0n || paused !== false || allowed.some((item) => item !== true)) {
|
|
323
|
+
throw new Error("The deployed Safe and module state does not match the locally approved policy.");
|
|
324
|
+
}
|
|
319
325
|
}
|
|
320
326
|
return {
|
|
321
327
|
enableSignature: await signParsedSafeTx(account, safe, enable),
|
|
@@ -362,7 +368,10 @@ export async function signLiveKeyGrant(prepared, privateKey, expected) {
|
|
|
362
368
|
}
|
|
363
369
|
return account.signMessage({ message });
|
|
364
370
|
}
|
|
365
|
-
|
|
371
|
+
// Engine risk_authorizer.policy.ALLOWED_VENUES, in its order
|
|
372
|
+
// (LIGHTER_CAPITAL_2026_10_06 added lighter).
|
|
373
|
+
export const RISK_MANDATE_VENUE_LIST = ["derive", "hyperliquid", "hyperliquid_spot", "lighter", "polymarket"];
|
|
374
|
+
const RISK_MANDATE_VENUES = RISK_MANDATE_VENUE_LIST.join(",");
|
|
366
375
|
export async function signRiskMandate(prepared, expected, privateKey) {
|
|
367
376
|
const account = ownerAccount(privateKey);
|
|
368
377
|
const owner = address(prepared.owner, "mandate owner");
|
package/dist/safe-policy.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { bytesToHex, createPublicClient, decodeFunctionData, encodeFunctionData, getAddress, hexToBytes, http, keccak256, parseAbi, } from "viem";
|
|
2
|
+
import { optionalPrivateRpc } from "./rpc-endpoints.js";
|
|
2
3
|
import { privateKeyToAccount } from "viem/accounts";
|
|
3
4
|
import { polygon } from "viem/chains";
|
|
4
5
|
import { getRuntimeOwnerPrivateKey } from "./secret-state.js";
|
|
@@ -21,7 +22,7 @@ const TOKEN_ADDRESSES = {
|
|
|
21
22
|
USDC: getAddress("0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359"),
|
|
22
23
|
pUSD: getAddress("0xC011a7E12a19f7B1f670d46F03B03f3342E82DFB"),
|
|
23
24
|
};
|
|
24
|
-
|
|
25
|
+
// NO_PUBLIC_RPC_20261115: never a public RPC (see optionalPrivateRpc).
|
|
25
26
|
const IMMUTABLE_RANGES = [
|
|
26
27
|
1657, 2125, 4182, 4918, 5477, 7704, 7737, 8082, 9251, 9772,
|
|
27
28
|
5700, 6717, 6838, 2167, 3947, 4692, 5182, 7300, 3980, 4725,
|
|
@@ -248,7 +249,12 @@ export function validatePreparedWithdrawal(prepared, expected, expectedOwner, no
|
|
|
248
249
|
};
|
|
249
250
|
}
|
|
250
251
|
async function assertPreparedWithdrawalSafeState(tx) {
|
|
251
|
-
const
|
|
252
|
+
const privateRpc = optionalPrivateRpc("polygon");
|
|
253
|
+
// Without the user's own private RPC this local chain check is skipped: Felix's engine,
|
|
254
|
+
// which verifies the Safe with its own quorum, is trusted exactly as the app does.
|
|
255
|
+
if (!privateRpc)
|
|
256
|
+
return;
|
|
257
|
+
const client = createPublicClient({ chain: polygon, transport: http(privateRpc) });
|
|
252
258
|
const [chainId, bytecode, singletonSlot, owners, threshold, nonce] = await Promise.all([
|
|
253
259
|
client.getChainId(),
|
|
254
260
|
client.getBytecode({ address: tx.safe }),
|
|
@@ -350,32 +356,37 @@ export async function signPreparedSafePolicy(prepared, expectedAction, privateKe
|
|
|
350
356
|
throw new Error("Felix returned the wrong Safe pause policy.");
|
|
351
357
|
}
|
|
352
358
|
}
|
|
353
|
-
const
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
client
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
||
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
359
|
+
const privateRpc = optionalPrivateRpc("polygon");
|
|
360
|
+
// Without the user's own private RPC this local chain check is skipped: Felix's engine,
|
|
361
|
+
// which verifies the Safe with its own quorum, is trusted exactly as the app does.
|
|
362
|
+
if (privateRpc) {
|
|
363
|
+
const client = createPublicClient({ chain: polygon, transport: http(privateRpc) });
|
|
364
|
+
const [chainId, safeBytecode, singletonSlot, moduleBytecode, multisendBytecode, owners, threshold, enabled, boundSafe, chainNonce] = await Promise.all([
|
|
365
|
+
client.getChainId(),
|
|
366
|
+
client.getBytecode({ address: safe }),
|
|
367
|
+
client.getStorageAt({ address: safe, slot: `0x${"00".repeat(32)}` }),
|
|
368
|
+
client.getBytecode({ address: module }),
|
|
369
|
+
expectedAction === "lockdown" ? client.getBytecode({ address: MULTISEND_CALL_ONLY }) : Promise.resolve(undefined),
|
|
370
|
+
client.readContract({ address: safe, abi: SAFE_ABI, functionName: "getOwners" }),
|
|
371
|
+
client.readContract({ address: safe, abi: SAFE_ABI, functionName: "getThreshold" }),
|
|
372
|
+
client.readContract({ address: safe, abi: SAFE_ABI, functionName: "isModuleEnabled", args: [module] }),
|
|
373
|
+
client.readContract({ address: module, abi: MODULE_ABI, functionName: "safe" }),
|
|
374
|
+
client.readContract({ address: safe, abi: SAFE_ABI, functionName: "nonce" }),
|
|
375
|
+
]);
|
|
376
|
+
const singleton = singletonSlot && singletonSlot.length >= 42
|
|
377
|
+
? getAddress(`0x${singletonSlot.slice(-40)}`)
|
|
378
|
+
: undefined;
|
|
379
|
+
if (chainId !== 137 || !safeBytecode || singleton?.toLowerCase() !== SAFE_SINGLETON.toLowerCase()
|
|
380
|
+
|| !moduleBytecode || normalizedRuntimeHash(moduleBytecode).toLowerCase() !== EXPECTED_RUNTIME_HASH
|
|
381
|
+
|| owners.length !== 1 || getAddress(owners[0]).toLowerCase() !== owner.toLowerCase()
|
|
382
|
+
|| threshold !== 1n || !enabled || getAddress(boundSafe).toLowerCase() !== safe.toLowerCase()
|
|
383
|
+
|| chainNonce !== BigInt(String(message.nonce))) {
|
|
384
|
+
throw new Error("The on-chain Safe identity, owner, module binding, or nonce does not match Felix V3.");
|
|
385
|
+
}
|
|
386
|
+
if (expectedAction === "lockdown"
|
|
387
|
+
&& (!multisendBytecode || keccak256(multisendBytecode).toLowerCase() !== MULTISEND_RUNTIME_HASH)) {
|
|
388
|
+
throw new Error("The on-chain MultiSendCallOnly runtime is not canonical Safe v1.3.0.");
|
|
389
|
+
}
|
|
379
390
|
}
|
|
380
391
|
const signTypes = { SafeTx: SAFE_TX_FIELDS };
|
|
381
392
|
return account.signTypedData({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "felix-mcp",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.129",
|
|
4
4
|
"mcpName": "trade.felix/mcp",
|
|
5
5
|
"description": "Non-custodial trading infrastructure for AI agents: one wallet, one risk policy, every market.",
|
|
6
6
|
"homepage": "https://felix.trade/docs",
|
|
@@ -114,7 +114,19 @@
|
|
|
114
114
|
"test:r234": "node --test test_r234_compatibility.mjs",
|
|
115
115
|
"test:owner-templates": "node test_owner_canary_templates.mjs",
|
|
116
116
|
"test:safe-coverage": "node --test test_safe_coverage_allow_list.mjs",
|
|
117
|
-
"test:secfix": "node scripts/test-secfix.mjs"
|
|
117
|
+
"test:secfix": "node scripts/test-secfix.mjs",
|
|
118
|
+
"test:venue-app-policy": "node test_venue_app_policy.mjs",
|
|
119
|
+
"test:arc-hypercore-driver": "node test_arc_hypercore_driver.mjs",
|
|
120
|
+
"test:arc-hypercore-return-driver": "node test_arc_hypercore_return_driver.mjs",
|
|
121
|
+
"test:arc-hypercore-stdio-restart": "node test_arc_hypercore_stdio_restart.mjs",
|
|
122
|
+
"test:arc-hypercore-return-stdio-restart": "node test_arc_hypercore_return_stdio_restart.mjs",
|
|
123
|
+
"test:public-venue": "node test_public_venue.mjs",
|
|
124
|
+
"test:mandate-venues": "node test_mandate_venues.mjs",
|
|
125
|
+
"test:no-public-rpc": "node test_no_public_rpc_defaults.mjs",
|
|
126
|
+
"test:arc-safe-invalidation-driver": "node test_arc_safe_invalidation_driver.mjs",
|
|
127
|
+
"test:arc-safe-invalidation-stdio-restart": "node test_arc_safe_invalidation_stdio_restart.mjs",
|
|
128
|
+
"test:arc-fee-topup-signer": "node test_arc_fee_topup_signer.mjs",
|
|
129
|
+
"test:arc-fee-topup-recovery": "node test_arc_fee_topup_recovery.mjs"
|
|
118
130
|
},
|
|
119
131
|
"keywords": [
|
|
120
132
|
"mcp",
|
package/server.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"name": "trade.felix/mcp",
|
|
4
4
|
"title": "Felix MCP",
|
|
5
5
|
"description": "Non-custodial trading infrastructure for AI agents across prediction markets, crypto, and options.",
|
|
6
|
-
"version": "2.0.
|
|
6
|
+
"version": "2.0.129",
|
|
7
7
|
"websiteUrl": "https://felix.trade/docs",
|
|
8
8
|
"icons": [
|
|
9
9
|
{
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
{
|
|
26
26
|
"registryType": "npm",
|
|
27
27
|
"identifier": "felix-mcp",
|
|
28
|
-
"version": "2.0.
|
|
28
|
+
"version": "2.0.129",
|
|
29
29
|
"transport": {
|
|
30
30
|
"type": "stdio"
|
|
31
31
|
}
|