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

Test updates #243

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
41 changes: 41 additions & 0 deletions docs/p2p.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,44 @@ Example:
```
./skandha node --redirectRpc --executor.bundlingMode manual --dataDir ./db2 --api.port 14339 --p2p.port 4339 --p2p.enrPort 4339 --p2p.bootEnrs [enr]
```

## Use Fastlane relayer

Use this config values to switch to fastlane relayer which protects bundles from MEV on Polygon

```json
{
"entryPoints": [
"0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789"
],
"relayers": [
"0xYOUR_PRIVATE_KEY"
],
"rpcEndpoint": "https://polygon.blockpi.network/v1/rpc/public ",
"canonicalMempoolId": "QmRJ1EPhmRDb8SKrPLRXcUBi2weUN8VJ8X9zUtXByC7eJg",
"canonicalEntryPoint": "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789",
"relayingMode": "fastlane",
"conditionalTransactions": true,
"rpcEndpointSubmit": "https://polygon-test-rpc.fastlane.xyz",
"fastlaneValidators": [
"0x127685D6dD6683085Da4B6a041eFcef1681E5C9C"
],
"bundleInterval": 2500
}

```

`canonicalMempoolId` - is the mempool id to which you want to connect\
`canonicalEntryPoint` - entry point that corresponds to canonical mempool id\
`rpcEndpointSubmit` - rpc endpoint provided by fastlane that supports `pfl_sendRawTransactionConditional` rpc method\
`fastlaneValidators` - addresses of validators that support `pfl_sendRawTransactionConditional` rpc method\
`bundleInterval` - this should be about the same value as block time on Polygon. On each interval Skandha will check if the current proposer matches `fastlaneValidators`, and if so submits the bundle


### Notes of Fastlane

Right now a very limited number of validators are participating in this, so in order to submit bundles Skandha has to wait for the right validator's turn, which usually takes hours and may take even longer.

### The list of fastlane validators

- `0x127685D6dD6683085Da4B6a041eFcef1681E5C9C`
1 change: 0 additions & 1 deletion packages/contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
"lint:natspec": "npx @defi-wonderland/natspec-smells --config natspec-smells.config.js",
"lint:sol-logic": "solhint -c .solhint.json 'src/**/*.sol' 'script/**/*.sol'",
"lint:sol-tests": "solhint -c .solhint.tests.json 'test/**/*.sol'",
"test": "forge test -vvv",
"test:integration": "forge test --match-contract Integration -vvv",
"test:unit": "forge test --match-contract Unit -vvv",
"test:unit:deep": "FOUNDRY_FUZZ_RUNS=5000 yarn test:unit"
Expand Down
2 changes: 2 additions & 0 deletions packages/executor/src/modules/eth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,8 @@ export class Eth {
validAfter: BigNumber.from(validAfter),
validUntil: BigNumber.from(validUntil),
callGasLimit,
maxFeePerGas: 0,
maxPriorityFeePerGas: 0,
};
}

Expand Down
6 changes: 4 additions & 2 deletions packages/executor/test/constants.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { constants } from "ethers";
import { StakeInfo } from "../src/interfaces";

export const TestAccountMnemonic = "test test test test test test test test test test test junk";
export const TestAccountMnemonic =
"test test test test test test test test test test test junk";
export const EntryPointAddress = "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789";
export const SimpleFactoryAddress = "0x6Cf2534C6AA425F20fb6A15FC836C8DD7e8f14e3";
export const SimpleFactoryAddress =
"0x6Cf2534C6AA425F20fb6A15FC836C8DD7e8f14e3";
export const DefaultRpcUrl = "http://127.0.0.1:8545";
export const NetworkName = "anvil";
export const ChainId = 31337;
Expand Down
52 changes: 35 additions & 17 deletions packages/executor/test/fixtures/getClient.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import { exec } from "child_process";
import { now, wait } from "../../src/utils";
import { exec } from "node:child_process";
import { BytesLike, hexConcat, hexZeroPad, hexlify } from "ethers/lib/utils";
import { IEntryPoint__factory, SimpleAccountFactory__factory } from "@skandha/types/src/executor/contracts";
import { DefaultRpcUrl, EntryPointAddress } from "../constants";
import {
IEntryPoint__factory,
SimpleAccountFactory__factory,
} from "@skandha/types/src/executor/contracts";
import { Wallet, constants, providers, utils } from "ethers";
import { DefaultRpcUrl, EntryPointAddress } from "../constants";
import { now, wait } from "../../src/utils";
import { testAccounts } from "./accounts";

let provider: providers.JsonRpcProvider;

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
export async function getClient() {
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
if (provider) return provider;
await runAnvil();
provider = new providers.JsonRpcProvider(DefaultRpcUrl);
Expand All @@ -17,17 +22,19 @@ export async function getClient() {
return provider;
}

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
export async function getWallet(index: number = 0) {
const client = await getClient();
return new Wallet(testAccounts[index], client);
}

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
async function runAnvil() {
exec("anvil");
const time = now();
while (now() < time + 5000) {
try {
let provider = new providers.JsonRpcProvider(DefaultRpcUrl);
const provider = new providers.JsonRpcProvider(DefaultRpcUrl);
(await provider.getNetwork()).chainId;
return;
} catch (err) {
Expand All @@ -36,17 +43,23 @@ async function runAnvil() {
}
}

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
export async function deployEntryPointAndFactory() {
await deployContractDeterministically(IEntryPoint__factory.bytecode);
await deployContractDeterministically((new SimpleAccountFactory__factory()).getDeployTransaction(EntryPointAddress).data!);
await deployContractDeterministically(
new SimpleAccountFactory__factory().getDeployTransaction(EntryPointAddress)
.data!
);
}

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
export async function deployDetermisticDeployer() {
const contractAddress = '0x4e59b44847b379578588920ca78fbf26c0b4956c'
const factoryTx = '0xf8a58085174876e800830186a08080b853604580600e600039806000f350fe7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe03601600081602082378035828234f58015156039578182fd5b8082525050506014600cf31ba02222222222222222222222222222222222222222222222222222222222222222a02222222222222222222222222222222222222222222222222222222222222222'
const factoryDeployer = '0x3fab184622dc19b6109349b94811493bf2a45362'
const deploymentGasPrice = 100e9
const deploymentGasLimit = 100000
const contractAddress = "0x4e59b44847b379578588920ca78fbf26c0b4956c";
const factoryTx =
"0xf8a58085174876e800830186a08080b853604580600e600039806000f350fe7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe03601600081602082378035828234f58015156039578182fd5b8082525050506014600cf31ba02222222222222222222222222222222222222222222222222222222222222222a02222222222222222222222222222222222222222222222222222222222222222";
const factoryDeployer = "0x3fab184622dc19b6109349b94811493bf2a45362";
const deploymentGasPrice = 100e9;
const deploymentGasLimit = 100000;
const factoryDeploymentFee = deploymentGasPrice * deploymentGasLimit;

const deployedBytecode = await provider.getCode(contractAddress);
Expand All @@ -56,18 +69,21 @@ export async function deployDetermisticDeployer() {
let tx = await wallet.sendTransaction({
to: factoryDeployer,
value: BigInt(factoryDeploymentFee),
nonce: await wallet.getTransactionCount()
})
nonce: await wallet.getTransactionCount(),
});
await tx.wait();
tx = await provider.sendTransaction(factoryTx);
await tx.wait();
} catch (err) {}
} catch (err) {
/* empty */
}
}

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
export async function deployContractDeterministically(bytecode: BytesLike) {
const salt = constants.HashZero;
const saltBytes32 = hexZeroPad(hexlify(salt), 32);
const deployerAddress = '0x4e59b44847b379578588920ca78fbf26c0b4956c';
const deployerAddress = "0x4e59b44847b379578588920ca78fbf26c0b4956c";
const bytecodeHash = utils.keccak256(bytecode);
const address = utils.getCreate2Address(deployerAddress, salt, bytecodeHash);
const deployedBytecode = await provider.getCode(address);
Expand All @@ -77,9 +93,11 @@ export async function deployContractDeterministically(bytecode: BytesLike) {
const tx = await wallet.sendTransaction({
to: deployerAddress,
data: hexConcat([saltBytes32, bytecode]),
nonce: await wallet.getTransactionCount()
nonce: await wallet.getTransactionCount(),
});
await tx.wait();
} catch (err) { }
} catch (err) {
/* empty */
}
return address;
}
2 changes: 2 additions & 0 deletions packages/executor/test/fixtures/getConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ let config: Config,
configUnsafe: Config,
networkConfigUnsafe: NetworkConfig;

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
export async function getConfigs() {
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
if (!config) {
config = await Config.init(BaseConfig);
networkConfig = config.getNetworkConfig();
Expand Down
1 change: 1 addition & 0 deletions packages/executor/test/fixtures/modules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { logger } from "../mocks/logger";
import { Web3, Debug, Eth } from "../../src/modules";
import { getServices } from "./services";

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
export async function getModules(config: Config, networkConfig: NetworkConfig) {
const provider = config.getNetworkProvider()!;
const {
Expand Down
1 change: 1 addition & 0 deletions packages/executor/test/fixtures/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { ChainId } from "../constants";
import { logger } from "../mocks/logger";
import { Skandha } from "../../src/modules";

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
export async function getServices(
config: Config,
networkConfig: NetworkConfig
Expand Down
Loading
Loading