Skip to content
Draft
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
6 changes: 1 addition & 5 deletions packages/bodhi/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
/* eslint-disable prefer-promise-reject-errors */
import { BigNumber } from '@ethersproject/bignumber';
import { BodhiProvider } from '@acala-network/eth-providers';
import { BodhiSigner } from './BodhiSigner';
import { BytesLike } from '@ethersproject/bytes';
import { KeyringPair } from '@polkadot/keyring/types';
import { WsProvider } from '@polkadot/api';
import { bufferToU8a, isBuffer, isU8a, u8aToHex } from '@polkadot/util';
import { createTestPairs } from '@polkadot/keyring';

export const U32MAX = BigNumber.from('0xffffffff');
export const U64MAX = BigNumber.from('0xffffffffffffffff');
import { BodhiSigner } from './BodhiSigner';

export const dataToString = (bytes: BytesLike): string => {
if (isBuffer(bytes)) {
Expand Down
4 changes: 2 additions & 2 deletions packages/eth-providers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"test:e2e": "vitest --run --config vitest.config.e2e.ts"
},
"peerDependencies": {
"@acala-network/api": "6.1.0",
"@acala-network/api": "^6.1.3",
"@polkadot/api": "^10.11.1"
},
"dependencies": {
Expand All @@ -23,7 +23,7 @@
"lru-cache": "~7.8.2"
},
"devDependencies": {
"@acala-network/api": "6.1.0",
"@acala-network/api": "^6.1.3",
"@types/bn.js": "~5.1.0",
"@types/lru-cache": "~7.6.1",
"dotenv": "~10.0.0",
Expand Down
Binary file not shown.
44 changes: 44 additions & 0 deletions packages/eth-providers/src/__tests__/e2e/trace.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { afterAll, describe, expect, it } from 'vitest';

import { EvmRpcProvider } from '../../rpc-provider';

const LOCAL_NODE_WITH_TRACING = 'ws://localhost:8000';
const ACALA_SUBQL = 'https://subql-query-acala.aca-api.network';

describe('tracing', async () => {
const provider = EvmRpcProvider.from(LOCAL_NODE_WITH_TRACING, { subqlUrl: ACALA_SUBQL });
await provider.isReady();

afterAll(async () => {
await provider.disconnect();
});

describe('trace calls', () => {
const tracerConf = { tracer: 'callTracer' };

it('send native token', async () => {
const trace = await provider.traceTx('0x89dd673cd8527943939904cb0d1f11992a9fd60a171ad7588c4dedf8712cfb7c', tracerConf);
expect(trace).to.toMatchSnapshot();
});

it('transfer erc20', async () => {
const trace = await provider.traceTx('0xf93095f41414f28b09866553ba2ac9957d865f32b6d2b0e220b08ff20e47612a', tracerConf);
expect(trace).to.toMatchSnapshot();
});

it('euphrates stake', async () => {
const trace = await provider.traceTx('0x16a70b2202ceb4968dcd1c44ee782a145a51bf016b92cc871b25ca5723ceffc8', tracerConf);
expect(trace).to.toMatchSnapshot();
});

// it('dex swap', async () => {
// const trace = await provider.traceTx('0x42c61da1a663e7c097399b2031d6bc38e0dff083e04de7083e145884bbfe8d9f', tracerConf);
// expect(trace).to.toMatchSnapshot();
// });
});

// describe('trace opcodes', () => {
// const tracerConf = { tracer: 'opcodeTracer' };
// });

});
33 changes: 33 additions & 0 deletions packages/eth-providers/src/base-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ import {
import { BlockCache, CacheInspect } from './utils/BlockCache';
import { MaxSizeSet } from './utils/MaxSizeSet';
import { SubqlProvider } from './utils/subqlProvider';
import { TracerType, traceCall, traceVM } from './utils/trace';
import { _Metadata } from './utils/gqlTypes';

export interface HeadsInfo {
Expand Down Expand Up @@ -2164,4 +2165,36 @@ export abstract class BaseProvider extends AbstractProvider {
listeners = (_eventName?: EventType): Array<Listener> => throwNotImplemented('listeners');
off = (_eventName: EventType, _listener?: Listener): Provider => throwNotImplemented('off');
removeAllListeners = (_eventName?: EventType): Provider => throwNotImplemented('removeAllListeners');

traceTx = async (txHash: string, traceConf: any) => {
const tracerOptions = Object.values(TracerType);
if (!tracerOptions.includes(traceConf.tracer)) {
logger.throwError(
`traceTx: invalid tracer, must be one of { ${tracerOptions.join(', ')} }`,
Logger.errors.INVALID_ARGUMENT,
{ tracer: traceConf.tracer },
);
}

if (!this.api.call.evmTraceApi) {
logger.throwError('traceTx: evm tracing not supported', Logger.errors.NOT_IMPLEMENTED, { txHash });
}

const receipt = await this.getReceipt(txHash);
if (!receipt) {
logger.throwError('traceTx: tx not found', Logger.errors.UNKNOWN_ERROR, { txHash });
}

const blockData = await this.api.rpc.chain.getBlock(receipt.blockHash);

const targetExtrinsic = blockData.block.extrinsics.find(ex => ex.hash.toHex() === txHash);
if (!targetExtrinsic) {
// if receipt can be found, but no evm extrinsic, it's either orphan or batch tx
logger.throwError('traceTx: tracing for orphan/batch tx is not supported', Logger.errors.UNKNOWN_ERROR, { txHash });
}

return traceConf.tracer === TracerType.CallTracer
? await traceCall(this.api, targetExtrinsic)
: await traceVM(this.api, targetExtrinsic);
};
}
97 changes: 0 additions & 97 deletions packages/eth-providers/src/consts.ts

This file was deleted.

14 changes: 14 additions & 0 deletions packages/eth-providers/src/consts/gas.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { BigNumber } from 'ethers';

export const BLOCK_GAS_LIMIT = 29_990_016;
export const BLOCK_STORAGE_LIMIT = 3_670_016;
export const MAX_GAS_LIMIT_CC = 21; // log2(BLOCK_STORAGE_LIMIT)

export const ONE_GWEI = 1_000_000_000n;
export const TEN_GWEI = ONE_GWEI * 10n;
export const ONE_HUNDRED_GWEI = ONE_GWEI * 100n;
export const ONE_THOUSAND_GWEI = ONE_GWEI * 1000n;

export const GAS_MASK = 100000;
export const STORAGE_MASK = 100;
export const GAS_LIMIT_CHUNK = BigNumber.from(30000);
5 changes: 5 additions & 0 deletions packages/eth-providers/src/consts/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export * from './gas';
export * from './misc';
export * from './msgs';
export * from './trace';
export * from './tx';
16 changes: 16 additions & 0 deletions packages/eth-providers/src/consts/misc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { BigNumber } from '@ethersproject/bignumber';

export const ZERO = 0;
export const EMPTY_HEX_STRING = '0x';

export const BIGNUMBER_ZERO = BigNumber.from(ZERO);
export const U32_MAX = 4_294_967_295n;

export const U32MAX = BigNumber.from('0xffffffff');
export const U64MAX = BigNumber.from('0xffffffffffffffff');

export const ERROR_PATTERN = [
// Assume that Error is nested only once
/execution fatal: Module\(ModuleError { index: (\d+), error: \[(\d+), 0, 0, 0\], message: None }\)/,
/execution fatal: Module\(ModuleError { index: (\d+), error: (\d+), message: None }\)/,
];
26 changes: 26 additions & 0 deletions packages/eth-providers/src/consts/msgs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
export const LOCAL_MODE_MSG = `
-------------------------------
🔨 local development mode is ON
❌ don't use it for production!
-------------------------------
`;

export const PROD_MODE_MSG = `
------------------------------------------
⚡️ running in production (standard) mode ⚡️
------------------------------------------
`;

export const SAFE_MODE_WARNING_MSG = `
------------------------------- WARNING -----------------------------
🔒 SafeMode is ON, and RPCs behave very differently than usual world!
❗ This mode is DEPRECATED, please use \`finalized\` block tag
---------------------------------------------------------------------
`;

export const CACHE_SIZE_WARNING = `
------------------- WARNING -------------------
Max cached blocks is big, please be cautious!
If memory exploded, try decrease MAX_CACHE_SIZE
-----------------------------------------------
`;
Loading