diff --git a/i_hate_json_rpc.rs b/i_hate_json_rpc.rs new file mode 100644 index 0000000..c9fa33f --- /dev/null +++ b/i_hate_json_rpc.rs @@ -0,0 +1,84 @@ +use curl::easy::Easy; +use ethers::providers::{Http, Middleware, Provider}; +use ethers::signers::{LocalWallet, Signer}; +use ethers::types::transaction::eip2718::TypedTransaction; +use ethers::types::{ + Address, Bytes, Eip1559TransactionRequest, Eip2930TransactionRequest, TransactionRequest, + TxHash, H160, U256, U64, +}; +use std::io::Read; +use std::str::FromStr; +use std::thread; +use std::time::Duration; + +// const RPC_URL: &str = "https://devnet.neonevm.org/"; +// const RPC_URL: &str = "https://proxy.devnet.neonlabs.org/solana"; +const RPC_URL: &str = "https://proxy.devnet.neonlabs.org/ethereum"; +// const RPC_URL: &str = "https://neon-mainnet.everstake.one"; +// const RPC_URL: &str = "https://virginia.rpc.blxrbdn.com"; + +#[tokio::main] +async fn main() { + println!("This is peak developer performance"); + let pk = "5da86377230463d7979cc45f985f13ed600ce572534e45f9a1240ae7fb08da5f"; + let wallet = LocalWallet::from_str(pk).unwrap(); + assert_eq!( + wallet.address(), + Address::from_str("0xBEEf734581018284bdBa6144750206bfA41edf7D").unwrap() + ); + let provider = Provider::::try_from(RPC_URL).unwrap(); + let gas_price: u128 = 25000000000000000; + let mut nonce = provider + .get_transaction_count(wallet.address(), None) + .await + .unwrap(); + // let mut nonce = U256::from(10000); + loop { + let mut tx_req = TransactionRequest::new(); + tx_req = tx_req.from(wallet.address()); + tx_req = tx_req.to(wallet.address()); + // tx_req = tx_req.value(U256::zero()); + tx_req = tx_req.value(U256::from(1)); + tx_req = tx_req.gas(U256::from(21000)); + tx_req = tx_req.gas_price(U256::from(gas_price)); + tx_req = tx_req.chain_id(U64::from(245022926)); + tx_req = tx_req.data(Bytes::from_str("").unwrap()); + tx_req = tx_req.nonce(nonce + 1); + dbg!(&tx_req); + let tx = TypedTransaction::Legacy(tx_req.clone()); + let signature = wallet.sign_transaction(&tx).await.unwrap(); + let rlp_signed = tx_req.rlp_signed(&signature); + dbg!(&rlp_signed); + // let ret = provider + // .send_raw_transaction(rlp_signed.clone()) + // .await + // .unwrap() + // .confirmations(1) + // .await + // .unwrap(); + // dbg!(&ret); + + nonce += U256::from(1); + println!("nonce: {}", nonce); + + let data = format!("{{\"jsonrpc\": \"2.0\", \"method\": \"eth_sendRawTransaction\", \"id\": {}, \"params\": [\"{}\"]}}", 1, rlp_signed); + dbg!(&data); + let mut data = data.as_bytes(); + + let mut easy = Easy::new(); + easy.url(RPC_URL).unwrap(); + easy.post(true).unwrap(); + easy.post_field_size(data.len() as u64).unwrap(); + let mut transfer = easy.transfer(); + let mut res = data.clone(); + transfer + .read_function(|buf| Ok(data.read(buf).unwrap_or(0))) + .unwrap(); + transfer.perform().unwrap(); + + // dbg!(data); + + thread::sleep(Duration::from_secs(20)); + } +} + diff --git a/lib/lyra-protocol b/lib/lyra-protocol index e8ba739..65856e4 160000 --- a/lib/lyra-protocol +++ b/lib/lyra-protocol @@ -1 +1 @@ -Subproject commit e8ba7390f82316b8be8634de9fa94c5f9556806f +Subproject commit 65856e433a9bfdccd38c5fe423ad252ab4bbdc49 diff --git a/src/Sneed.sol b/src/Sneed.sol index e2b2b9a..d411128 100644 --- a/src/Sneed.sol +++ b/src/Sneed.sol @@ -26,10 +26,13 @@ contract Sneed is BaseHook, OptionChoice { uint256 private currentActiveContracts = 0; int256 ethBalanceBefore; + uint256 ethRemainder; address private kahjitAddress; address private chainlinkAddress; + uint256 public accumulatedEth; + constructor(IPoolManager _poolManager, address _kahjitAddress, bool _gonnaBeEth, address _chainlinkAddress) BaseHook(_poolManager) { kahjitAddress = _kahjitAddress; gonnaBeEth = _gonnaBeEth; @@ -80,18 +83,20 @@ contract Sneed is BaseHook, OptionChoice { contractAmount = amount1; } - // get how much eth we're depositing, since its going to be whole we need to truncate the decimals - contractAmount = contractAmount / 1e18; + accumulatedEth += contractAmount; + if (accumulatedEth >= 1e18) { + (,int256 answer,,,) = AggregatorV3Interface(chainlinkAddress).latestRoundData(); - (,int256 answer,,,) = AggregatorV3Interface(chainlinkAddress).latestRoundData(); + IKahjit(kahjitAddress).buyOptions( + accumulatedEth / 1e18, + uint64(whichStrike(uint256(answer))), + uint64((block.timestamp + 30 days)), + 10, + true + ); - IKahjit(kahjitAddress).buyOptions( - contractAmount, - uint64(whichStrike(uint256(answer))), - uint64((block.timestamp + 30 days)), - 10, - true - ); + accumulatedEth %= 1e18; // this is the first time the word ever see this operator + } return BaseHook.beforeSwap.selector; } @@ -116,14 +121,12 @@ contract Sneed is BaseHook, OptionChoice { _checkActive(); int256 ethBalanceDelta = int256(IERC20(Currency.unwrap(key.currency0)).balanceOf(address(this))) - ethBalanceBefore; + accumulatedEth = 0; // empty the accumulated amount - // Implying we have 18 decimals - ethBalanceDelta = ethBalanceDelta / 1e18; (,int256 answer,,,) = AggregatorV3Interface(chainlinkAddress).latestRoundData(); // if delta is positive, buy options if (ethBalanceDelta > 0) { - IKahjit(kahjitAddress).buyOptions( uint256(ethBalanceDelta), uint64(whichStrike(uint256(answer))),