Skip to content

Commit 6a1098c

Browse files
author
vcart
committed
chore: cleaned, reviewed and simplified core/
1 parent 93bcad9 commit 6a1098c

13 files changed

Lines changed: 1660 additions & 723 deletions

File tree

README.md

Lines changed: 471 additions & 76 deletions
Large diffs are not rendered by default.

src/core/chains.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/**
22
* Defines supported Starknet networks with their RPC URLs
33
*/
4+
import { constants } from 'starknet';
45

56
export type NetworkConfig = {
67
name: string;
@@ -12,12 +13,12 @@ export type NetworkConfig = {
1213
const networks: Record<string, NetworkConfig> = {
1314
mainnet: {
1415
name: 'mainnet',
15-
chainId: 'SN_MAIN',
16+
chainId: constants.StarknetChainId.SN_MAIN,
1617
rpcUrl: 'https://starknet-mainnet.public.blastapi.io'
1718
},
1819
sepolia: {
1920
name: 'sepolia',
20-
chainId: 'SN_SEPOLIA',
21+
chainId: constants.StarknetChainId.SN_SEPOLIA,
2122
rpcUrl: 'https://starknet-sepolia.public.blastapi.io'
2223
}
2324
};

src/core/resources.ts

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ export function registerResources(server: McpServer) {
2525
network,
2626
blockNumber,
2727
rpcUrl
28-
}),
28+
}, (key, value) =>
29+
typeof value === 'bigint' ? value.toString() : value),
2930
mimeType: "application/json"
3031
}]
3132
};
@@ -88,7 +89,8 @@ export function registerResources(server: McpServer) {
8889
return {
8990
contents: [{
9091
uri: uri.toString(),
91-
text: JSON.stringify(block),
92+
text: JSON.stringify(block, (key, value) =>
93+
typeof value === 'bigint' ? value.toString() : value),
9294
mimeType: "application/json"
9395
}]
9496
};
@@ -119,7 +121,8 @@ export function registerResources(server: McpServer) {
119121
return {
120122
contents: [{
121123
uri: uri.toString(),
122-
text: JSON.stringify(block),
124+
text: JSON.stringify(block, (key, value) =>
125+
typeof value === 'bigint' ? value.toString() : value),
123126
mimeType: "application/json"
124127
}]
125128
};
@@ -146,28 +149,30 @@ export function registerResources(server: McpServer) {
146149
const network = params.network as string;
147150
const address = params.address as string;
148151

149-
const ethBalance = await services.getETHBalance(address, network);
152+
// Try to resolve the address if it's a StarkNet ID
153+
const resolvedAddress = await services.utils.resolveNameOrAddress(address, network);
154+
const ethBalance = await services.getETHBalance(resolvedAddress, network);
150155
const provider = services.getProvider(network);
151-
const formattedAddress = services.parseStarknetAddress(address);
152156

153157
// Get class hash and class
154-
const classHash = await provider.getClassHashAt(formattedAddress, 'latest');
158+
const classHash = await provider.getClassHashAt(resolvedAddress, 'latest');
155159
const contractClass = await provider.getClass(classHash, 'latest');
156160

157161
// Get Starknet ID if available
158-
const starknetId = await services.getStarkName(address, network);
162+
const starknetId = await services.getStarkName(resolvedAddress, network);
159163

160164
return {
161165
contents: [{
162166
uri: uri.toString(),
163167
text: JSON.stringify({
164-
address: formattedAddress,
168+
address: resolvedAddress,
165169
ethBalance,
166170
classHash,
167171
contractType: contractClass.abi ? "Contract" : "EOA",
168172
starknetId: starknetId || null,
169173
hasStarknetId: !!starknetId
170-
}),
174+
}, (key, value) =>
175+
typeof value === 'bigint' ? value.toString() : value),
171176
mimeType: "application/json"
172177
}]
173178
};
@@ -205,7 +210,8 @@ export function registerResources(server: McpServer) {
205210
text: JSON.stringify({
206211
transaction,
207212
receipt
208-
}),
213+
}, (key, value) =>
214+
typeof value === 'bigint' ? value.toString() : value),
209215
mimeType: "application/json"
210216
}]
211217
};
@@ -309,15 +315,18 @@ export function registerResources(server: McpServer) {
309315
const network = params.network as string;
310316
const address = params.address as string;
311317

312-
const profile = await services.getStarkProfile(address, network);
318+
// Try to resolve the address if it's a StarkNet ID
319+
const resolvedAddress = await services.utils.resolveNameOrAddress(address, network);
320+
const profile = await services.getStarkProfile(resolvedAddress, network);
313321

314322
return {
315323
contents: [{
316324
uri: uri.toString(),
317325
text: JSON.stringify(profile || {
318-
address,
326+
address: resolvedAddress,
319327
id: null
320-
}),
328+
}, (key, value) =>
329+
typeof value === 'bigint' ? value.toString() : value),
321330
mimeType: "application/json"
322331
}]
323332
};

0 commit comments

Comments
 (0)