Skip to content

Commit 93bcad9

Browse files
committed
fix: fixing bugs // WIP
1 parent 48c4b8d commit 93bcad9

9 files changed

+205
-314
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
"cors": "^2.8.5",
4646
"express": "^4.21.2",
4747
"starknet": "^6.23.1",
48+
"starknetid.js": "3.0.2",
4849
"zod": "^3.24.2"
4950
},
5051
"keywords": [

src/core/services/balance.ts

+8-23
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,10 @@ import { uint256, num } from 'starknet';
33
import { CallData } from 'starknet';
44
import { utils as helpers } from './utils.js';
55

6-
// Token contract addresses by network
7-
type NetworkAddresses = {
8-
[key: string]: string;
9-
};
10-
11-
const TOKEN_ADDRESSES: {
12-
ETH: NetworkAddresses;
13-
STRK: NetworkAddresses;
14-
} = {
15-
// ETH contract addresses
16-
ETH: {
17-
mainnet: '0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7',
18-
sepolia: '0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7'
19-
},
20-
// STRK contract addresses
21-
STRK: {
22-
mainnet: '0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d',
23-
sepolia: '0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d'
24-
}
6+
// Token contract addresses (same for all networks)
7+
const TOKEN_ADDRESSES = {
8+
ETH: '0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7',
9+
STRK: '0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d'
2510
};
2611

2712
/**
@@ -54,7 +39,7 @@ export async function getETHBalance(
5439
const formattedAddress = parseStarknetAddress(address);
5540

5641
// ETH is managed by the ETH contract
57-
const contractAddress = TOKEN_ADDRESSES.ETH[network as keyof typeof TOKEN_ADDRESSES.ETH] || TOKEN_ADDRESSES.ETH.mainnet;
42+
const contractAddress = TOKEN_ADDRESSES.ETH;
5843
const ethContract = getContract(contractAddress, provider, network);
5944

6045
// Get the class hash to fetch the ABI
@@ -90,7 +75,7 @@ export async function getSTRKBalance(
9075
const formattedAddress = parseStarknetAddress(address);
9176

9277
// STRK token contract
93-
const contractAddress = TOKEN_ADDRESSES.STRK[network as keyof typeof TOKEN_ADDRESSES.STRK] || TOKEN_ADDRESSES.STRK.mainnet;
78+
const contractAddress = TOKEN_ADDRESSES.STRK;
9479
const strkContract = getContract(contractAddress, provider, network);
9580

9681
// Get the class hash to fetch the ABI
@@ -161,7 +146,7 @@ export async function getERC20Balance(
161146
}
162147
}> {
163148
// Check if this is a native token request
164-
if (tokenAddress.toLowerCase() === TOKEN_ADDRESSES.ETH[network as keyof typeof TOKEN_ADDRESSES.ETH].toLowerCase()) {
149+
if (tokenAddress.toLowerCase() === TOKEN_ADDRESSES.ETH.toLowerCase()) {
165150
const balance = await getETHBalance(ownerAddress, network);
166151
return {
167152
raw: balance.wei,
@@ -171,7 +156,7 @@ export async function getERC20Balance(
171156
decimals: 18
172157
}
173158
};
174-
} else if (tokenAddress.toLowerCase() === TOKEN_ADDRESSES.STRK[network as keyof typeof TOKEN_ADDRESSES.STRK].toLowerCase()) {
159+
} else if (tokenAddress.toLowerCase() === TOKEN_ADDRESSES.STRK.toLowerCase()) {
175160
const balance = await getSTRKBalance(ownerAddress, network);
176161
return {
177162
raw: balance.wei,

src/core/services/clients.ts

+11-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,17 @@ export function getProvider(network = 'mainnet'): RpcProvider {
2525

2626
// Create a new provider
2727
const rpcUrl = getRpcUrl(network);
28-
const chainId = getChainId(network);
28+
29+
// Map network name to Starknet.js chain ID constants
30+
let chainId;
31+
if (network === 'mainnet') {
32+
chainId = constants.StarknetChainId.SN_MAIN;
33+
} else if (network === 'sepolia') {
34+
chainId = constants.StarknetChainId.SN_SEPOLIA;
35+
} else {
36+
// Default to mainnet if network is unknown
37+
chainId = constants.StarknetChainId.SN_MAIN;
38+
}
2939

3040
const provider = new RpcProvider({
3141
nodeUrl: rpcUrl,

src/core/services/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export * from './transactions.js';
88
export * from './transfer.js';
99
export * from './starknetid.js';
1010
export { utils as helpers } from './utils.js';
11+
export { utils } from './utils.js';
1112

1213
// Re-export common types for convenience
1314
export type {

0 commit comments

Comments
 (0)