Skip to content
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
84 changes: 84 additions & 0 deletions i_hate_json_rpc.rs
Original file line number Diff line number Diff line change
@@ -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::<Http>::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));
}
}

2 changes: 1 addition & 1 deletion lib/lyra-protocol
Submodule lyra-protocol updated 108 files
29 changes: 16 additions & 13 deletions src/Sneed.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand All @@ -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))),
Expand Down