Skip to content

Commit

Permalink
Add more networks
Browse files Browse the repository at this point in the history
  • Loading branch information
anastasiarods committed Jan 5, 2024
1 parent 2d920d7 commit eeef78a
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 11 deletions.
22 changes: 20 additions & 2 deletions apps/web/src/app/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,30 @@ export const supportedChains = [
{
name: "Ethereum Mainnet",
chainID: 1,
rpcUrl: process.env.MAINNET_RPC_URL as string,
rpcUrl:
(process.env.MAINNET_RPC_URL as string) || "https://rpc.ankr.com/eth",
},
{
name: "Goerli Testnet",
chainID: 5,
rpcUrl: process.env.GOERLI_RPC_URL as string,
rpcUrl:
(process.env.GOERLI_RPC_URL as string) ||
"https://rpc.ankr.com/eth_goerli",
},
{
name: "Base mainnet",
chainID: 8453,
rpcUrl: process.env.BASE_RPC_URL as string,
supportTraceAPI: false,
batching: false,
},
{
name: "Manta pacific",
chainID: 169,
rpcUrl:
(process.env.MANTA_RPC_URL as string) ||
"https://pacific-rpc.manta.network/http",
supportTraceAPI: false,
},
];

Expand Down
23 changes: 17 additions & 6 deletions apps/web/src/lib/contract-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
ContractMetaStore,
EtherscanStrategyResolver,
SourcifyStrategyResolver,
BlockscoutStrategyResolver,
RPCProvider,
} from "@3loop/transaction-decoder";
import { Effect, Layer } from "effect";
Expand All @@ -20,6 +21,11 @@ export const AbiStoreLive = Layer.succeed(
}),
SourcifyStrategyResolver(),
],
169: [
BlockscoutStrategyResolver({
endpoint: "https://pacific-explorer.manta.network/api",
}),
],
},
set: ({ address = {} }) =>
Effect.gen(function* (_) {
Expand All @@ -30,12 +36,17 @@ export const AbiStoreLive = Layer.succeed(
Effect.all(
addressMatches.map(([key, value]) =>
Effect.promise(() =>
prisma.contractAbi.create({
data: {
address: key.toLowerCase(),
abi: value,
},
}),
prisma.contractAbi
.create({
data: {
address: key,
abi: value,
},
})
.catch((e) => {
console.error("Failed to cache abi", e);
return null;
}),
),
),
{
Expand Down
3 changes: 3 additions & 0 deletions apps/web/src/lib/etherscan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ const endpoints: { [k: number]: string } = {
3: "https://api-ropsten.etherscan.io/api",
4: "https://api-rinkeby.etherscan.io/api",
5: "https://api-goerli.etherscan.io/api",
8453: "https://api.basescan.org/api",
84531: "https://api-goerli.basescan.org/api",
84532: "https://api-sepolia.basescan.org/api",
};

export interface Transfer {
Expand Down
8 changes: 6 additions & 2 deletions apps/web/src/lib/rpc-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,20 @@ export function getProvider(chainID: number): RPCProviderObject | null {
if (provider != null) {
return provider;
}

const url = providerConfigs[chainID]?.rpcUrl;

if (url != null) {
const batchMaxCount = providerConfigs[chainID]?.batching ? 100 : 1;

provider = {
provider: new JsonRpcProvider(url),
provider: new JsonRpcProvider(url, undefined, {
batchMaxCount: batchMaxCount,
}),
config: {
supportTraceAPI: providerConfigs[chainID]?.supportTraceAPI,
},
};

providers[chainID] = provider;
return provider;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ const endpoints: { [k: number]: string } = {
4: 'https://api-rinkeby.etherscan.io/api',
5: 'https://api-goerli.etherscan.io/api',
11155111: 'https://api-sepolia.etherscan.io/api',
8453: 'https://api.basescan.org/api',
84531: 'https://api-goerli.basescan.org/api',
84532: 'https://api-sepolia.basescan.org/api',
}

async function fetchContractABI(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export class ResolveStrategyABIError {
) {}
}

//NOTE: we store address as key to be able to know adddress to abi mapping for caching
export interface ContractABI {
address?: Record<string, string>
func?: Record<string, string>
Expand Down
21 changes: 21 additions & 0 deletions packages/transaction-decoder/src/helpers/networks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
export const chainIdToNetwork: { [key: number]: string } = {
1: 'mainnet',
3: 'ropsten',
4: 'rinkeby',
5: 'goerli',
42: 'kovan',
11155111: 'sepolia',
42161: 'arbitrum',
421613: 'arbitrum-goerli',
8453: 'base',
84531: 'base-goerli',
84532: 'base-sepolia',
56: 'bnb',
97: 'bnbt',
137: 'polygon',
80001: 'mumbai',
59144: 'linea',
59140: 'linea-goerli',
169: 'manta-pacific',
3441005: 'manta-pacific-testnet',
}
3 changes: 2 additions & 1 deletion packages/transaction-decoder/src/transaction-decoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { getProxyStorageSlot } from './decoding/proxies.js'
import { getAndCacheAbi } from './abi-loader.js'
import { getAndCacheContractMeta } from './contract-meta-loader.js'
import traverse from 'traverse'
import { chainIdToNetwork } from './helpers/networks.js'

export class UnsupportedEvent {
readonly _tag = 'UnsupportedEvent'
Expand Down Expand Up @@ -194,7 +195,7 @@ export const decodeTransaction = ({
},
traceCalls: decodedTraceRight,
nativeValueSent: value,
chainSymbol: Network.from(Number(transaction.chainId)).name,
chainSymbol: chainIdToNetwork[Number(transaction.chainId)] ?? 'unknown',
chainID: Number(transaction.chainId),
interactions,
effectiveGasPrice: receipt.gasPrice.toString(),
Expand Down

0 comments on commit eeef78a

Please sign in to comment.