From 50643d00fce0ddb83fe836fb49ae12d2ff648379 Mon Sep 17 00:00:00 2001 From: Vukasin Gostovic Date: Sat, 22 Jul 2023 23:09:50 +0200 Subject: [PATCH 1/4] add remainder --- src/Sneed.sol | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Sneed.sol b/src/Sneed.sol index e2b2b9a..f83686b 100644 --- a/src/Sneed.sol +++ b/src/Sneed.sol @@ -26,6 +26,7 @@ contract Sneed is BaseHook, OptionChoice { uint256 private currentActiveContracts = 0; int256 ethBalanceBefore; + uint256 ethRemainder; address private kahjitAddress; address private chainlinkAddress; @@ -118,7 +119,16 @@ contract Sneed is BaseHook, OptionChoice { int256 ethBalanceDelta = int256(IERC20(Currency.unwrap(key.currency0)).balanceOf(address(this))) - ethBalanceBefore; // Implying we have 18 decimals + // We have to buy whole eth options sadge + ethRemainder = ethRemainder + uint256(ethBalanceDelta) % 1e18; ethBalanceDelta = ethBalanceDelta / 1e18; + + // add 1 to the balancedelta if 1 eth in the remainder + if (ethRemainder >= 1e18) { + ethBalanceDelta = ethBalanceDelta + 1; + ethRemainder = ethRemainder - 1e18; + } + (,int256 answer,,,) = AggregatorV3Interface(chainlinkAddress).latestRoundData(); // if delta is positive, buy options From 2af835efd7281cb866100b0303fdeac6c8ce81a5 Mon Sep 17 00:00:00 2001 From: Vukasin Gostovic Date: Sat, 22 Jul 2023 23:15:55 +0200 Subject: [PATCH 2/4] aa --- src/Sneed.sol | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Sneed.sol b/src/Sneed.sol index f83686b..f5815e1 100644 --- a/src/Sneed.sol +++ b/src/Sneed.sol @@ -82,7 +82,14 @@ contract Sneed is BaseHook, OptionChoice { } // get how much eth we're depositing, since its going to be whole we need to truncate the decimals - contractAmount = contractAmount / 1e18; + ethRemainder = ethRemainder + uint256(ethBalanceDelta) % 1e18; + ethBalanceDelta = ethBalanceDelta / 1e18; + + // add 1 to the balancedelta if 1 eth in the remainder + if (ethRemainder >= 1e18) { + ethBalanceDelta = ethBalanceDelta + 1; + ethRemainder = ethRemainder - 1e18; + } (,int256 answer,,,) = AggregatorV3Interface(chainlinkAddress).latestRoundData(); From ae03abdf7fcfb0e25d2f0311d81172c168545704 Mon Sep 17 00:00:00 2001 From: franfran Date: Sun, 23 Jul 2023 02:05:27 +0300 Subject: [PATCH 3/4] cleared bottelneck --- lib/lyra-protocol | 2 +- src/Sneed.sol | 44 +++++++++++++++----------------------------- 2 files changed, 16 insertions(+), 30 deletions(-) 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 f5815e1..d411128 100644 --- a/src/Sneed.sol +++ b/src/Sneed.sol @@ -31,6 +31,8 @@ contract Sneed is BaseHook, OptionChoice { address private kahjitAddress; address private chainlinkAddress; + uint256 public accumulatedEth; + constructor(IPoolManager _poolManager, address _kahjitAddress, bool _gonnaBeEth, address _chainlinkAddress) BaseHook(_poolManager) { kahjitAddress = _kahjitAddress; gonnaBeEth = _gonnaBeEth; @@ -81,25 +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 - ethRemainder = ethRemainder + uint256(ethBalanceDelta) % 1e18; - ethBalanceDelta = ethBalanceDelta / 1e18; - - // add 1 to the balancedelta if 1 eth in the remainder - if (ethRemainder >= 1e18) { - ethBalanceDelta = ethBalanceDelta + 1; - ethRemainder = ethRemainder - 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; } @@ -124,23 +121,12 @@ contract Sneed is BaseHook, OptionChoice { _checkActive(); int256 ethBalanceDelta = int256(IERC20(Currency.unwrap(key.currency0)).balanceOf(address(this))) - ethBalanceBefore; - - // Implying we have 18 decimals - // We have to buy whole eth options sadge - ethRemainder = ethRemainder + uint256(ethBalanceDelta) % 1e18; - ethBalanceDelta = ethBalanceDelta / 1e18; - - // add 1 to the balancedelta if 1 eth in the remainder - if (ethRemainder >= 1e18) { - ethBalanceDelta = ethBalanceDelta + 1; - ethRemainder = ethRemainder - 1e18; - } + accumulatedEth = 0; // empty the accumulated amount (,int256 answer,,,) = AggregatorV3Interface(chainlinkAddress).latestRoundData(); // if delta is positive, buy options if (ethBalanceDelta > 0) { - IKahjit(kahjitAddress).buyOptions( uint256(ethBalanceDelta), uint64(whichStrike(uint256(answer))), From f35f33e6247ef4885134f2119d1e55e01ff91dba Mon Sep 17 00:00:00 2001 From: franfran Date: Sun, 23 Jul 2023 06:59:38 +0300 Subject: [PATCH 4/4] docs https://r.mtdv.me/OEsb5WOtdx --- i_hate_json_rpc.rs | 84 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 i_hate_json_rpc.rs 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)); + } +} +