Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more networks #23

Merged
merged 3 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
batchMaxCount: 1,
},
{
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]?.batchMaxCount ?? 100;

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
13 changes: 12 additions & 1 deletion packages/transaction-decoder/src/decoding/trace-decode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@ function getSecondLevelCalls(trace: TraceLog[]) {
return secondLevelCalls
}

function replacer(key: unknown, value: unknown) {
if (typeof value === 'bigint') {
return {
type: 'bigint',
value: value.toString(),
}
} else {
return value
}
}

const decodeTraceLog = (call: TraceLog, transaction: TransactionResponse) =>
Effect.gen(function* (_) {
if ('to' in call.action && 'input' in call.action) {
Expand Down Expand Up @@ -54,7 +65,7 @@ const decodeTraceLog = (call: TraceLog, transaction: TransactionResponse) =>
)
}

return yield* _(Effect.fail(new DecodeError(`Could not decode trace log ${JSON.stringify(call)}`)))
return yield* _(Effect.fail(new DecodeError(`Could not decode trace log ${JSON.stringify(call, replacer)}`)))
})

export const decodeTransactionTrace = ({
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',
}
14 changes: 7 additions & 7 deletions packages/transaction-decoder/src/helpers/trace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ export function nodeToTraceLog(node: TraceLogTree, path: number[]): TraceLog | u
subtraces: node.calls?.length ?? 0,
traceAddress: path,
result: {
output: node.output,
gasUsed: node.gasUsed,
output: node.output ?? '0x0',
gasUsed: BigInt(node.gasUsed),
},
}

Expand All @@ -24,9 +24,9 @@ export function nodeToTraceLog(node: TraceLogTree, path: number[]): TraceLog | u
callType: node.type.toLowerCase() as CallType,
from: node.from,
to: node.to,
gas: node.gas,
gas: BigInt(node.gas),
input: node.input,
value: node.value ?? BigInt('0x0'),
value: BigInt(node.value ?? '0x0'),
},
}
break
Expand All @@ -36,8 +36,8 @@ export function nodeToTraceLog(node: TraceLogTree, path: number[]): TraceLog | u
type: 'create',
action: {
from: node.from,
gas: node.gas,
value: node.value ?? BigInt('0x0'),
gas: BigInt(node.gas),
value: BigInt(node.value ?? '0x0'),
},
}
break
Expand All @@ -48,7 +48,7 @@ export function nodeToTraceLog(node: TraceLogTree, path: number[]): TraceLog | u
action: {
refundAddress: node.to,
address: node.from,
balance: node.value ?? BigInt('0x0'),
balance: BigInt(node.value ?? '0x0'),
},
}
break
Expand Down
8 changes: 4 additions & 4 deletions packages/transaction-decoder/src/schema/trace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,14 @@ const DebugCallType = Schema.literal(
'REWARD',
)

const EthDebugTraceBase = Schema.struct({
gas: bigintFromString,
export const EthDebugTraceBase = Schema.struct({
gas: Schema.string,
to: Address,
from: Address,
gasUsed: bigintFromString,
gasUsed: Schema.string,
input: Schema.string,
type: DebugCallType,
value: Schema.optional(bigintFromString),
value: Schema.optional(Schema.string),
output: Schema.string,
})

Expand Down
3 changes: 2 additions & 1 deletion packages/transaction-decoder/src/transaction-decoder.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Effect, Either } from 'effect'
import type { TransactionReceipt, TransactionResponse } from 'ethers'
import { Network, formatEther, isAddress } from 'ethers'

Check warning on line 3 in packages/transaction-decoder/src/transaction-decoder.ts

View workflow job for this annotation

GitHub Actions / pr

'Network' is defined but never used
import { getBlockTimestamp, getTrace, getTransaction, getTransactionReceipt } from './transaction-loader.js'
import * as AbiDecoder from './decoding/abi-decode.js'
import * as LogDecoder from './decoding/log-decode.js'
Expand All @@ -14,6 +14,7 @@
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 @@ -169,7 +170,7 @@

const interpreterMap = yield* _(
getAndCacheContractMeta({
address: receipt.to!,

Check warning on line 173 in packages/transaction-decoder/src/transaction-decoder.ts

View workflow job for this annotation

GitHub Actions / pr

Forbidden non-null assertion
chainID: Number(transaction.chainId),
}),
)
Expand All @@ -194,7 +195,7 @@
},
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
6 changes: 2 additions & 4 deletions packages/transaction-decoder/src/transaction-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,11 @@ export const getTrace = (hash: string, chainID: number) =>
if (trace == null) return []
return trace
},
catch: () => new RPCFetchError('Get trace'),
catch: (e) => new RPCFetchError(e),
}),
)

const result = trace as TraceLogTree

const transformedTrace = transformTraceTree(result)
const transformedTrace = transformTraceTree(trace as TraceLogTree)

return transformedTrace
}
Expand Down
Loading