{"id":15626533,"url":"https://github.com/sambacha/q-evm","last_synced_at":"2025-10-04T04:36:02.503Z","repository":{"id":38414729,"uuid":"482650266","full_name":"sambacha/q-evm","owner":"sambacha","description":"MEV Bot and Flashbots Bundler written in q using kdb+","archived":false,"fork":false,"pushed_at":"2022-09-15T22:47:07.000Z","size":458,"stargazers_count":424,"open_issues_count":0,"forks_count":92,"subscribers_count":12,"default_branch":"master","last_synced_at":"2025-07-14T07:44:51.087Z","etag":null,"topics":["bot","defi","ethereum","evm","flashbots","foundry","hevm","kdb","kx","mev","q","qlang","solidity"],"latest_commit_sha":null,"homepage":"","language":"q","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sambacha.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-04-17T22:48:27.000Z","updated_at":"2025-06-13T11:08:35.000Z","dependencies_parsed_at":"2022-07-16T23:31:12.194Z","dependency_job_id":null,"html_url":"https://github.com/sambacha/q-evm","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/sambacha/q-evm","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sambacha%2Fq-evm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sambacha%2Fq-evm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sambacha%2Fq-evm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sambacha%2Fq-evm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sambacha","download_url":"https://codeload.github.com/sambacha/q-evm/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sambacha%2Fq-evm/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265625570,"owners_count":23800624,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bot","defi","ethereum","evm","flashbots","foundry","hevm","kdb","kx","mev","q","qlang","solidity"],"created_at":"2024-10-03T10:12:54.466Z","updated_at":"2025-10-04T04:35:57.459Z","avatar_url":"https://github.com/sambacha.png","language":"q","funding_links":[],"categories":["MEV \u0026 Arbitrage"],"sub_categories":["Solana Trading"],"readme":"\n# kdb+/q for EVM\n\n\u003e [What is kdb+/q?, see kx.com](https://kx.com)\n\n\n## Overview\n\nkdb+ adapted for usage on Ethereum/EVM Chains\n\nThis code is no longer in usage at Manifold Finance, which is why we have open sourced it.\n\n\n## Setup\n\n\u003e**Warning**      \n\u003e  mortals require instructions, you have been warned.\n\n\n1. [You will need a license for kdb+ to use this, here is the install instructions via code.kx.com](https://code.kx.com/q/learn/install/)\n\n2. [Get the 64bit License via the On-Demand Personal exemption](https://kx.com/64bit-on-demand-personal-edition/)\n\n\n## Required Libraries\n\nThese libraries are *required*\n\n[https://github.com/manifoldfinance/qBigInt](https://github.com/manifoldfinance/qBigInt)\n\n[https://github.com/manifoldfinance/qQuarticRoots](https://github.com/manifoldfinance/qQuarticRoots)\n\n[https://github.com/manifoldfinance/qAbiEncode](https://github.com/manifoldfinance/qAbiEncode)\n\n\n## Example: Aave\n\n[see /aave dir](/aave)\n\n![](https://d.pr/i/K4XegR.jpeg)\n\nWill start 4 processes.\n\nq realtime db for user balances.    \nsubscribe to all lender events to update db balances.      \nquery snapshot of every user balance (will take a long time to complete but liquidations can still occur in the background).     \nscan for unstable health and try to liquidate (prompt will appear for unlocking your accounts).   \nlogs folder will hold log info.   \n\nTo view live user balances and health: `http://localhost:5010`.    \n\n## Utils\n\n[Jupyter Notebook for Sushiswap/Uniswap Liquidity and Market Depth](https://gist.github.com/sambacha/a21955e8a8feec7579a607f153476547#file-sushiswap_liquiditypairs-ipynb)\n\n## Install\n\nFrom https://code.kx.com/q4m3/14_Introduction_to_Kdb+/1481-the-environment-variables,\nset `QHOME` to the location of `q.k`.\nTo pass in a license, invoke q with `QLIC` set to the *directory* in which\n`kc.lic` is located.\nOther .q (or .k) files are loaded with `\\l path/to/file`.\n`.so `files are loaded by defining their name/path when defining the function:\n\n## Flashbots Overview\n\nhttps://docs.flashbots.net/flashbots-auction/overview\n\nNotes on the current state of flashbots docs with relevance to assumptions of bundle process.\n\n### Anatomy of a bundle\n\n```ts\nconst blockNumber = await provider.getBlockNumber()\nconst minTimestamp = (await provider.getBlock(blockNumber)).timestamp\nconst maxTimestamp = minTimestamp + 120\nconst signedBundle = flashbotsProvider.signBundle(\n    [\n      {\n        signedTransaction: SIGNED_ORACLE_UPDATE_FROM_PENDING_POOL // serialized signed transaction hex\n      },\n      {\n        signer: wallet, // ethers signer\n        transaction: transaction // ethers populated transaction object\n      }\n    ])\nconst bundleReceipt = await flashbotsProvider.sendRawBundle(\n    signedBundle, // bundle we signed above\n    targetBlockNumber, // block number at which this bundle is valid\n    {\n      minTimestamp, // optional minimum timestamp at which this bundle is valid (inclusive)\n      maxTimestamp, // optional maximum timestamp at which this bundle is valid (inclusive)\n      revertingTxHashes: [tx1, tx2] // optional list of transaction hashes allowed to revert. Without specifying here, any revert invalidates the entire bundle.\n    }\n  )\n)\n```\n\n### Miner reward through coinbase.transfer()\n\nhttps://docs.flashbots.net/flashbots-auction/searchers/advanced/coinbase-payment\n\nTo include as last action of smart contract\n\n```solidity\nblock.coinbase.transfer(AMOUNT_TO_TRANSFER)\n\n```\n\nEdge case to deal with sending to a miner contract\n```solidity\nblock.coinbase.call{value: _ethAmountToCoinbase}(new bytes(0));\n```\nsubject to [reentrancy attacks](https://medium.com/coinmonks/protect-your-solidity-smart-contracts-from-reentrancy-attacks-9972c3af7c21)\n\n### Bundle pricing\n\nhttps://docs.flashbots.net/flashbots-auction/searchers/advanced/bundle-pricing\n\nConflicting bundles received by flashbots are ordered by the following formula:\n\n![\\bg_white \\Large score=\\frac{minerBribe + totalGasUsed * priorityFeePerGas - mempoolGasUsed * priorityFeePerGas}{totalGasUsed}](https://latex.codecogs.com/png.latex?\\bg_white\u0026space;\\Large\u0026space;score=\\frac{minerBribe\u0026space;+\u0026space;totalGasUsed\u0026space;*\u0026space;priorityFeePerGas\u0026space;-\u0026space;mempoolGasUsed\u0026space;*\u0026space;priorityFeePerGas}{totalGasUsed})\n\n### Eligibility\n\nhttps://docs.flashbots.net/flashbots-auction/miners/mev-geth-spec/v04\n\nBundles must have a target `blockNumber` and a `priorityFeePerGas` \u003e= 1 Gwei.\n\n### Reverting txs\n\nhttps://docs.flashbots.net/flashbots-auction/miners/mev-geth-spec/v04\n\n\n\"When constructing a block the node should reject any bundle or megabundle that has a reverting transaction unless its hash is included in the RevertingTxHashes list of the bundle\"\n\n### Debugging\n\nhttps://docs-staging.flashbots.net/flashbots-auction/searchers/advanced/troubleshooting\n\n1. Transaction failure (ANY within the bundle)\n2. Incentives (gas price/coinbase transfers) not high enough to offset value of block space\n\nSimulate bundle:\n```ts\n  const signedTransactions = await flashbotsProvider.signBundle(transactionBundle)\n  const simulation = await flashbotsProvider.simulate(signedTransactions, targetBlockNumber, targetBlockNumber + 1)\n  console.log(JSON.stringify(simulation, null, 2))\n```\n\n3. Competitors paying more\n\nGet conflicting bundles for a prior block:\n```ts\nconst signedTransactions = await flashbotsProvider.signBundle(transactionBundle)\nconsole.log(await flashbotsProvider.getConflictingBundle(\n      signedTransactions,\n      13140328 // blockNumber\n  ))\n```\n\n4. Bundle received too late to appear in target block\n\nGet submission time data and compare to block time:\n```ts\nconsole.log(\n  await flashbotsProvider.getBundleStats(\"0x123456789abcdef123456789abcdef123456789abcdef123456789abcdef1234\", 13509887)\n  )\n\n```\n\n## License\n\n  This Source Code Form is subject to the terms of the Mozilla Public\n  License, v. 2.0. If a copy of the MPL was not distributed with this\n  file, You can obtain one at http://mozilla.org/MPL/2.0/.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsambacha%2Fq-evm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsambacha%2Fq-evm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsambacha%2Fq-evm/lists"}