Skip to content

Commit

Permalink
Merge branch 'main' into debug_single_solver_simulation_failure
Browse files Browse the repository at this point in the history
  • Loading branch information
fleupold authored Dec 15, 2023
2 parents 352c5dd + 2d3f53e commit c37a2d3
Show file tree
Hide file tree
Showing 19 changed files with 333 additions and 45 deletions.
9 changes: 9 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM mcr.microsoft.com/devcontainers/base:bullseye

RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
# Remove imagemagick due to https://security-tracker.debian.org/tracker/CVE-2019-10131
&& apt-get purge -y imagemagick imagemagick-6-common

# [Optional] Uncomment this section to install additional OS packages.
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
&& apt-get -y install --no-install-recommends gdb valgrind heaptrack
59 changes: 59 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"build": {
"dockerfile": "./Dockerfile",
"context": "."
},
"features": {
"ghcr.io/devcontainers/features/common-utils:2": {
"installZsh": true,
"configureZshAsDefaultShell": true,
"installOhMyZsh": true,
"installOhMyZshConfig": true,
"upgradePackages": true,
"username": "automatic",
"userUid": "automatic",
"userGid": "automatic"
},
"ghcr.io/devcontainers/features/rust:1": {},
"ghcr.io/devcontainers/features/git:1": {},
"ghcr.io/nlordell/features/foundry": {},
"ghcr.io/devcontainers/features/docker-in-docker:2": {
"dockerDashComposeVersion": "v2"
},
"ghcr.io/robbert229/devcontainer-features/postgresql-client:1": {},
"ghcr.io/devcontainers-contrib/features/zsh-plugins:0": {
"plugins": "npm git rust docker docker-compose git-prompt postgres",
"omzPlugins": "https://github.com/zsh-users/zsh-autosuggestions",
"username": "vscode"
}
},
"runArgs": [
"--cap-add=SYS_PTRACE",
"--security-opt",
"seccomp=unconfined"
],

"customizations": {
"vscode": {
"settings": {
"rust-analyzer.rustfmt.extraArgs": [
"+nightly"
]
},
"extensions": [
"rust-lang.rust-analyzer",
"serayuzgur.crates"
]
}
},

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],

// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "rustc --version",
"postCreateCommand": "rustup toolchain install nightly && cargo install flamegraph",

// Set `remoteUser` to `root` to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "vscode"
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ Run an `autopilot` with:

```sh
cargo run --bin autopilot -- \
--skip-event-sync \
--skip-event-sync true \
--node-url <YOUR_NODE_URL>
```

Expand Down
1 change: 1 addition & 0 deletions crates/contracts/artifacts/TestnetUniswapV2Router02.json
153 changes: 147 additions & 6 deletions crates/contracts/build.rs

Large diffs are not rendered by default.

26 changes: 17 additions & 9 deletions crates/contracts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ include_contracts! {
IUniswapV3Factory;
IZeroEx;
PancakeRouter;
SolverTrampoline;
SushiSwapRouter;
SwaprRouter;
TestnetUniswapV2Router02;
UniswapV2Factory;
UniswapV2Router02;
UniswapV3Pool;
Expand Down Expand Up @@ -93,6 +93,7 @@ mod tests {
const MAINNET: u64 = 1;
const GOERLI: u64 = 5;
const GNOSIS: u64 = 100;
const SEPOLIA: u64 = 11155111;

use {
super::*,
Expand Down Expand Up @@ -155,34 +156,41 @@ mod tests {
}};
}

for network in &[MAINNET, GOERLI, GNOSIS] {
for network in &[MAINNET, GOERLI, GNOSIS, SEPOLIA] {
assert_has_deployment_address!(GPv2Settlement for *network);
assert_has_deployment_address!(SushiSwapRouter for *network);
assert_has_deployment_address!(WETH9 for *network);
assert_has_deployment_address!(CowProtocolToken for *network);
assert_has_deployment_address!(HooksTrampoline for *network);
assert_has_deployment_address!(BalancerV2Vault for *network);
assert_has_deployment_address!(BalancerV2NoProtocolFeeLiquidityBootstrappingPoolFactory for *network);
}
for network in &[MAINNET, GOERLI, GNOSIS] {
assert_has_deployment_address!(SushiSwapRouter for *network);
}
for network in &[MAINNET, GOERLI, SEPOLIA] {
assert_has_deployment_address!(UniswapV3SwapRouter for *network);
assert_has_deployment_address!(IUniswapV3Factory for *network);
}
for network in &[MAINNET, GOERLI] {
assert_has_deployment_address!(BalancerV2Vault for *network);
assert_has_deployment_address!(BalancerV2WeightedPoolFactory for *network);
assert_has_deployment_address!(BalancerV2WeightedPool2TokensFactory for *network);
assert_has_deployment_address!(UniswapV2Factory for *network);
assert_has_deployment_address!(UniswapV2Router02 for *network);
assert_has_deployment_address!(UniswapV3SwapRouter for *network);
assert_has_deployment_address!(IUniswapV3Factory for *network);
}

// only mainnet
assert_has_deployment_address!(BalancerV2StablePoolFactoryV2 for MAINNET);
assert_has_deployment_address!(BalancerV2LiquidityBootstrappingPoolFactory for MAINNET);
assert_has_deployment_address!(BalancerV2NoProtocolFeeLiquidityBootstrappingPoolFactory for MAINNET);
assert_has_deployment_address!(PancakeRouter for MAINNET);
assert_has_deployment_address!(IZeroEx for MAINNET);

// only gnosis
assert_has_deployment_address!(BaoswapRouter for GNOSIS);
assert_has_deployment_address!(HoneyswapRouter for GNOSIS);
assert_has_deployment_address!(SwaprRouter for GNOSIS);

// only sepolia
assert_has_deployment_address!(TestnetUniswapV2Router02 for SEPOLIA);
}

#[test]
Expand All @@ -198,11 +206,11 @@ mod tests {
}};
}

for network in &[MAINNET, GOERLI, GNOSIS] {
for network in &[MAINNET, GOERLI, GNOSIS, SEPOLIA] {
assert_has_deployment_information!(GPv2Settlement for *network);
assert_has_deployment_information!(BalancerV2Vault for *network);
}
for network in &[MAINNET, GOERLI] {
assert_has_deployment_information!(BalancerV2Vault for *network);
assert_has_deployment_information!(BalancerV2WeightedPoolFactory for *network);
assert_has_deployment_information!(BalancerV2WeightedPool2TokensFactory for *network);
}
Expand Down
5 changes: 5 additions & 0 deletions crates/driver/src/boundary/mempool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ impl Kind {
}
}

/// Don't submit transactions with high revert risk (i.e. transactions
/// that interact with on-chain AMMs) to the public mempool.
/// This can be enabled to avoid MEV when private transaction
/// submission strategies are available. If private submission strategies
/// are not available, revert protection is always disabled.
#[derive(Debug, Clone, Copy)]
pub enum RevertProtection {
Enabled,
Expand Down
25 changes: 19 additions & 6 deletions crates/driver/src/infra/config/file/load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ pub async fn load(network: &blockchain::Network, path: &Path) -> infra::Config {
file::UniswapV2Preset::PancakeSwap => {
liquidity::config::UniswapV2::pancake_swap(&network.id)
}
file::UniswapV2Preset::TestnetUniswapV2 => {
liquidity::config::UniswapV2::testnet_uniswapv2(&network.id)
}
}
.expect("no Uniswap V2 preset for current network"),
file::UniswapV2Config::Manual {
Expand Down Expand Up @@ -264,12 +267,22 @@ pub async fn load(network: &blockchain::Network, path: &Path) -> infra::Config {
config.submission.retry_interval_secs,
),
kind: match mempool {
file::Mempool::Public { revert_protection } => {
mempool::Kind::Public(if *revert_protection {
mempool::RevertProtection::Enabled
} else {
mempool::RevertProtection::Disabled
})
file::Mempool::Public => {
// If there is no private mempool, revert protection is
// disabled, otherwise driver would not even try to settle revertable
// settlements
mempool::Kind::Public(
if config
.submission
.mempools
.iter()
.any(|pool| matches!(pool, file::Mempool::MevBlocker { .. }))
{
mempool::RevertProtection::Enabled
} else {
mempool::RevertProtection::Disabled
},
)
}
file::Mempool::MevBlocker {
url,
Expand Down
11 changes: 2 additions & 9 deletions crates/driver/src/infra/config/file/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,7 @@ struct SubmissionConfig {
#[serde(tag = "mempool")]
#[serde(rename_all = "kebab-case", deny_unknown_fields)]
enum Mempool {
#[serde(rename_all = "kebab-case")]
Public {
/// Don't submit transactions with high revert risk (i.e. transactions
/// that interact with on-chain AMMs) to the public mempool.
/// This can be enabled to avoid MEV when private transaction
/// submission strategies are available.
#[serde(default)]
revert_protection: bool,
},
Public,
#[serde(rename_all = "kebab-case")]
MevBlocker {
/// The MEVBlocker URL to use.
Expand Down Expand Up @@ -327,6 +319,7 @@ enum UniswapV2Preset {
Honeyswap,
Baoswap,
PancakeSwap,
TestnetUniswapV2,
}

#[derive(Clone, Debug, Deserialize)]
Expand Down
14 changes: 14 additions & 0 deletions crates/driver/src/infra/liquidity/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,20 @@ impl UniswapV2 {
missing_pool_cache_time: Duration::from_secs(60 * 60),
})
}

/// Returns the liquidity configuration for liquidity sources only used on
/// test networks.
pub fn testnet_uniswapv2(network: &eth::NetworkId) -> Option<Self> {
Some(Self {
router: deployment_address(
contracts::TestnetUniswapV2Router02::raw_contract(),
network,
)?,
pool_code: hex!("0efd7612822d579e24a8851501d8c2ad854264a1050e3dfcee8afcca08f80a86")
.into(),
missing_pool_cache_time: Duration::from_secs(60 * 60),
})
}
}

/// Swapr (Uniswap V2 clone with a twist) liquidity fetching options.
Expand Down
13 changes: 7 additions & 6 deletions crates/model/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,16 +165,17 @@ mod tests {
}

#[test]
fn domain_separator_goerli() {
fn domain_separator_sepolia() {
let contract_address: H160 = hex!("9008D19f58AAbD9eD0D60971565AA8510560ab41").into(); // new deployment
let chain_id: u64 = 5;
let domain_separator_goerli = DomainSeparator::new(chain_id, contract_address);
// domain separator is taken from goerli deployment at address
let chain_id: u64 = 11155111;
let domain_separator_sepolia = DomainSeparator::new(chain_id, contract_address);
// domain separator is taken from Sepolia deployment at address
// 0x9008D19f58AAbD9eD0D60971565AA8510560ab41
// https://sepolia.etherscan.io/address/0x9008d19f58aabd9ed0d60971565aa8510560ab41#readContract#F2
let expected_domain_separator = DomainSeparator(hex!(
"fb378b35457022ecc5709ae5dafad9393c1387ae6d8ce24913a0c969074c07fb"
"daee378bd0eb30ddf479272accf91761e697bc00e067a268f95f1d2732ed230b"
));
assert_eq!(domain_separator_goerli, expected_domain_separator);
assert_eq!(domain_separator_sepolia, expected_domain_separator);
}

#[test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ impl BlockscoutTokenOwnerFinder {
1 => "https://eth.blockscout.com/api",
5 => "https://eth-goerli.blockscout.com/api",
100 => "https://blockscout.com/xdai/mainnet/api",
11155111 => "https://eth-sepolia.blockscout.com/api",
_ => bail!("Unsupported Network"),
};

Expand Down
1 change: 1 addition & 0 deletions crates/shared/src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub fn block_interval(network_id: &str, chain_id: u64) -> Option<Duration> {
("1", 1) => 12,
("5", 5) => 12,
("100", 100) => 5,
("11155111", 11155111) => 12,
_ => return None,
}))
}
4 changes: 2 additions & 2 deletions crates/shared/src/price_estimation/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ pub type NativePriceEstimateResult = Result<f64, PriceEstimationError>;

pub fn default_amount_to_estimate_native_prices_with(chain_id: u64) -> Option<U256> {
match chain_id {
// Mainnet, Göŕli
1 | 5 => Some(10u128.pow(18).into()),
// Mainnet, Göŕli, Sepolia
1 | 5 | 11155111 => Some(10u128.pow(18).into()),
// Gnosis chain
100 => Some(10u128.pow(21).into()),
_ => None,
Expand Down
7 changes: 2 additions & 5 deletions crates/shared/src/sources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub enum BaselineSource {
Swapr,
ZeroEx,
UniswapV3,
TestnetUniswapV2,
}

pub fn defaults_for_chain(chain_id: u64) -> Result<Vec<BaselineSource>> {
Expand All @@ -38,11 +39,6 @@ pub fn defaults_for_chain(chain_id: u64) -> Result<Vec<BaselineSource>> {
BaselineSource::ZeroEx,
BaselineSource::UniswapV3,
],
4 => vec![
BaselineSource::UniswapV2,
BaselineSource::SushiSwap,
BaselineSource::BalancerV2,
],
5 => vec![
BaselineSource::UniswapV2,
BaselineSource::SushiSwap,
Expand All @@ -54,6 +50,7 @@ pub fn defaults_for_chain(chain_id: u64) -> Result<Vec<BaselineSource>> {
BaselineSource::Baoswap,
BaselineSource::Swapr,
],
11155111 => vec![BaselineSource::TestnetUniswapV2],
_ => bail!("unsupported chain {:#x}", chain_id),
})
}
Expand Down
6 changes: 6 additions & 0 deletions crates/shared/src/sources/balancer_v2/pool_fetching.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,12 @@ impl BalancerFactoryKind {
Self::ComposableStableV4,
Self::ComposableStableV5,
],
11155111 => vec![
Self::WeightedV4,
Self::ComposableStableV4,
Self::ComposableStableV5,
Self::NoProtocolFeeLiquidityBootstrapping,
],
_ => Default::default(),
}
}
Expand Down
Loading

0 comments on commit c37a2d3

Please sign in to comment.