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

fix: keystore mutex #17

Closed
wants to merge 28 commits into from
Closed
Changes from 2 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
2e2204b
support getting pk from aws secrets manager
ConjunctiveNormalForm Aug 29, 2024
cb81ace
Merge pull request #2 from Uniswap/support-aws-pk
ConjunctiveNormalForm Aug 29, 2024
4777bb0
fix: error handling (#1)
zhongeric Aug 29, 2024
100a12d
add reference docker file
ConjunctiveNormalForm Aug 29, 2024
5457881
Merge pull request #3 from Uniswap/add-docker
ConjunctiveNormalForm Aug 29, 2024
b79efe4
fix: Dockerfile
ConjunctiveNormalForm Aug 29, 2024
bf4c460
Merge pull request #4 from Uniswap/ConjunctiveNormalForm-patch-1
ConjunctiveNormalForm Aug 29, 2024
d8ebd18
feat: private key store and getters/setters (#5)
zhongeric Aug 29, 2024
20c59aa
wait for 1 confirmation before releasing key
zhongeric Sep 3, 2024
91b2cc6
set from address
zhongeric Sep 3, 2024
1d8ddf1
fix tracing logs format
zhongeric Sep 3, 2024
19e3fd2
Merge pull request #6 from Uniswap/feat-wait-for-confirmations
ConjunctiveNormalForm Sep 3, 2024
8bf5b95
Merge pull request #7 from Uniswap/fix-log-format
ConjunctiveNormalForm Sep 4, 2024
d3ef7ff
apt-get -y
ConjunctiveNormalForm Sep 4, 2024
7012fe4
Merge pull request #8 from Uniswap/fix-dockerfile
ConjunctiveNormalForm Sep 4, 2024
9761119
log receipt
ConjunctiveNormalForm Sep 6, 2024
3e649d4
log order hash
ConjunctiveNormalForm Sep 6, 2024
a08e4f7
logging
ConjunctiveNormalForm Sep 6, 2024
b6686b4
mod stuff
ConjunctiveNormalForm Sep 6, 2024
818ae26
log four bytes
ConjunctiveNormalForm Sep 9, 2024
e6249ee
log parsed
ConjunctiveNormalForm Sep 9, 2024
0eba8cb
Merge pull request #9 from Uniswap/more-logging
ConjunctiveNormalForm Sep 9, 2024
ce181e2
more structured logs
ConjunctiveNormalForm Sep 9, 2024
26d58e2
Merge remote-tracking branch 'origin/main' into more-logging
ConjunctiveNormalForm Sep 9, 2024
e58c805
fix format
ConjunctiveNormalForm Sep 9, 2024
04b5568
cargo fmt
ConjunctiveNormalForm Sep 9, 2024
e099a80
Merge pull request #10 from Uniswap/more-logging
ConjunctiveNormalForm Sep 10, 2024
d31de2a
fix keystore and add tests
zhongeric Sep 11, 2024
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
808 changes: 688 additions & 120 deletions Cargo.lock

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -29,3 +29,8 @@ alloy-primitives = "0.2.0"
serde_qs = "0.12.0"
async-stream = "0.3.5"
mockito = "1.1.0"

# aws
aws-config = { version = "1.1.7", features = ["behavior-version-latest"] }
aws-sdk-secretsmanager = "1.43.0"
serde_json = "1.0.127"
40 changes: 36 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use anyhow::Result;
use clap::Parser;
use clap::{ArgGroup, Parser};

use artemis_core::engine::Engine;
use artemis_core::types::{CollectorMap, ExecutorMap};
@@ -15,6 +15,7 @@ use ethers::{
};
use executors::protect_executor::ProtectExecutor;
use executors::public_1559_executor::Public1559Executor;
use std::collections::HashMap;
use std::sync::Arc;
use strategies::priority_strategy::UniswapXPriorityFill;
use strategies::{
@@ -33,14 +34,28 @@ const MEV_BLOCKER: &str = "https://rpc.mevblocker.io/noreverts";

/// CLI Options.
#[derive(Parser, Debug)]
#[command(group(
ArgGroup::new("Key_source")
.required(true)
.args(&["private_key", "aws_secret_arn"])
))]
pub struct Args {
/// Ethereum node WS endpoint.
#[arg(long)]
pub wss: String,

/// Private key for sending txs.
#[arg(long)]
pub private_key: String,
pub private_key: Option<String>,

/// public key for the bot that corresponds to the private key.
#[arg(long)]
pub bot_address: String,

/// AWS secret arn for fetching private key.
/// This is a secret manager arn that contains the private key as plain text.
#[arg(long)]
pub aws_secret_arn: Option<String>,

/// Percentage of profit to pay in gas.
#[arg(long)]
@@ -81,8 +96,25 @@ async fn main() -> Result<()> {
let mevblocker_provider =
Provider::<Http>::try_from(MEV_BLOCKER).expect("could not instantiate HTTP Provider");

let wallet: LocalWallet = args
.private_key
/// TODO: support an array of addresses
let pk = if let Some(aws_secret_arn) = args.aws_secret_arn {
let config = aws_config::load_from_env().await;
let client = aws_sdk_secretsmanager::Client::new(&config);
let pk_mapping_json = client.get_secret_value()
.secret_id(aws_secret_arn)
.send()
.await
.expect("could not get private key secret")
.secret_string
.expect("secret string not found");
let pk_mapping = serde_json::from_str::<HashMap<String, String>>(&pk_mapping_json)
.expect("could not parse private key mapping");
pk_mapping.get(&args.bot_address).unwrap().clone()
} else {
args.private_key.clone().unwrap()
};

let wallet: LocalWallet = pk
.parse::<LocalWallet>()
.unwrap()
.with_chain_id(chain_id);