{"id":23107760,"url":"https://github.com/kleros/action-callback-bots","last_synced_at":"2025-08-16T17:31:48.916Z","repository":{"id":34135554,"uuid":"168718996","full_name":"kleros/action-callback-bots","owner":"kleros","description":"Collection of bots that call contract action callbacks.","archived":false,"fork":false,"pushed_at":"2024-02-25T11:29:38.000Z","size":47808,"stargazers_count":7,"open_issues_count":7,"forks_count":3,"subscribers_count":12,"default_branch":"master","last_synced_at":"2024-04-26T00:41:49.750Z","etag":null,"topics":["backend","kleros-v1"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kleros.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2019-02-01T15:35:30.000Z","updated_at":"2024-04-26T00:41:49.751Z","dependencies_parsed_at":"2024-02-16T18:52:41.553Z","dependency_job_id":null,"html_url":"https://github.com/kleros/action-callback-bots","commit_stats":{"total_commits":118,"total_committers":14,"mean_commits":8.428571428571429,"dds":0.7457627118644068,"last_synced_commit":"a91aab56f061d34243f0d21e5dd05f52acc59d10"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kleros%2Faction-callback-bots","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kleros%2Faction-callback-bots/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kleros%2Faction-callback-bots/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kleros%2Faction-callback-bots/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kleros","download_url":"https://codeload.github.com/kleros/action-callback-bots/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230047188,"owners_count":18164575,"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":["backend","kleros-v1"],"created_at":"2024-12-17T01:16:04.031Z","updated_at":"2024-12-17T01:16:04.535Z","avatar_url":"https://github.com/kleros.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n  \u003cb style=\"font-size: 32px;\"\u003eAction Callback Bots | Web3 Batched Send\u003c/b\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://standardjs.com\"\u003e\u003cimg src=\"https://img.shields.io/badge/code_style-standard-brightgreen.svg\" alt=\"JavaScript Style Guide\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://travis-ci.org/kleros/action-callback-bots\"\u003e\u003cimg src=\"https://travis-ci.org/kleros/action-callback-bots.svg?branch=master\" alt=\"Build Status\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://conventionalcommits.org\"\u003e\u003cimg src=\"https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg\" alt=\"Conventional Commits\"\u003e\u003c/a\u003e\n  \u003ca href=\"http://commitizen.github.io/cz-cli/\"\u003e\u003cimg src=\"https://img.shields.io/badge/commitizen-friendly-brightgreen.svg\" alt=\"Commitizen Friendly\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://github.com/prettier/prettier\"\u003e\u003cimg src=\"https://img.shields.io/badge/styled_with-prettier-ff69b4.svg\" alt=\"Styled with Prettier\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\nThis repo houses a collection of bots that call smart contract action callbacks, and a utility for sending queued batches of transactions efficiently that is used in all of them. This utility is published as an npm package and since the code lives here, the rest of this document will document it.\n\n# Installation\n\n```sh\nnpm install --save web3-batched-send\n```\n\nor\n\n```sh\nyarn add web3-batched-send\n```\n\n# Why You Should Use It\n\n- Sending a batch of transactions costs less gas than sending them all individually.\n- When dealing with any non-trivial contract, you'll need to send transactions before previous ones have been mined. Dealing with nonces and gas prices in those cases is a pain, and depending on your approach, you can miss transactions or have one transaction with a low gas price blocking all the ones that come after. If you also want to do batching, it becomes even harder. This utility abstracts all of that away efficiently.\n- The \"eager and preemptive, but protected\" API makes it really easy to write bots. You can \"poke\" all the action callbacks of your contract every X minutes and be sure that you will never spend gas on a transaction that would fail.\n\n# How You Use It\n\n```js\nconst Web3 = require('web3')\nconst _batchedSend = require('batched-send')\nconst _contract = require('../assets/contracts/contract.json')\n\nconst web3 = new Web3(process.env.WEB3_PROVIDER_URL)\nconst batchedSend = _batchedSend(\n  web3, // Your web3 object.\n  // The address of the transaction batcher contract you wish to use. The addresses for the different networks are listed below. If the one you need is missing, feel free to deploy it yourself and make a PR to save the address here for others to use.\n  process.env.TRANSACTION_BATCHER_CONTRACT_ADDRESS,\n  process.env.PRIVATE_KEY, // The private key of the account you want to send transactions from.\n  60000 // The debounce timeout period in milliseconds in which transactions are batched.\n)\nconst contract = new web3.eth.Contract(\n  _contract.abi,\n  process.env.CONTRACT_ADDRESS\n)\n\nbatchedSend({\n  method: contract.methods.foo,\n  to: contract.options.address\n})\nbatchedSend([\n  // Also supports an array of transactions.\n  {\n    args: [a], // This is how you pass arguments.\n    method: contract.methods.foo,\n    to: contract.options.address\n  },\n  {\n    args: [b],\n    method: contract.methods.bar,\n    to: contract.options.address\n  },\n  {\n    args: [c],\n    method: contract.methods.baz,\n    to: contract.options.address\n  }\n])\n```\n\n## Transaction Batcher Contract Addresses\n\n- Mainnet: `0x82458d1c812d7c930bb3229c9e159cbabd9aa8cb`\n- Sepolia: `0x718e35BA29c1927e31CB66b6E5a3f187990c8108`\n- Gnosis Chain: `0x6426800F8508b15AED271337498fa5e7D0794d46`\n## Full Examples\n\nSee the `src/bots` folder in this repo.\n\n# What It Does\n\nIt batches all your transactions until the specified timeout elapses since the last time you added a transaction (classic debounce batch). After the timeout elapses, this batch is added to the list of current pending batches. Imagine we had already sent batches A, B, C, and D, but due to rising gas prices, they are still in the mempool. Your pending batches list would look like this:\n\n![Pending Batches 1](./assets/pending-batches-1.png)\n\nThe letters inside the batch represent the fact that whenever we send a batch transaction for a new batch, we include in it, the transactions of all previous batches. This is because the new batch transaction will share their nonce, and we don't want to lose the transactions of previous batches. Before sending the new batch transaction with the new median gas price, we take the opportunity to prune all pending batches of transactions that would now fail, to avoid wasting gas on failed transactions. If no transactions are left after the pruning, we just don't do anything. Note that the batching contract uses a low level call so even if a transaction still fails, it will not affect the others. After a batch transaction gets mined, because of the way we store pending batches, we can perform a really neat trick that ensures the algorithm has all the properties we want. We slice off the head of the list, up to and including the batch whose transaction got mined, and if any batches are left, we send a new batch transaction with their contents and essentially restart the whole flow with a new nonce.\n\n![Pending Batches 2](./assets/pending-batches-2.png)\n\nLeaving batch D in the list is not a problem, because it has an old nonce, it will never be mined and it will just be sliced off with the next batch transaction that gets mined.\n\n## The Smart Contract\n\n```js\n/// SPDX-License-Identifier: MIT\npragma solidity ~0.8.0;\n\ncontract TransactionBatcher {\n    function batchSend(address[] calldata targets, uint[] calldata values, bytes[] calldata datas) public payable {\n        for (uint i = 0; i \u003c targets.length; i++) {\n            targets[i].call{value: values[i]}(datas[i]);\n        }\n    }\n}\n```\n\n## Environment Variables\n\nTo run the bots in this repository, duplicate the `.env` file and rename the copy to either `.env.production` or `.env.staging`.\n\nBelow is an example of what a .env file would look like for deployments on the Kovan network.\n\n```\nWEB3_PROVIDER_URL=https://kovan.infura.io/v3/\u003capi-key\u003e\nTRANSACTION_BATCHER_CONTRACT_ADDRESS=0x741A4dCaD4f72B83bE9103a383911d78362611cf\nBATCH_SEND_PRIVATE_KEY=0x2E28195A4F392FC380024636A0D14980F726849CC55024A01BF842D16605CFEB\nKLEROS_LIQUID_CONTRACT_ADDRESS=0x60b2abfdfad9c0873242f59f2a8c32a3cc682f80\nMULTIPLE_ARBITRABLE_TRANSACTION_CONTRACT_ADDRESS=\nT2CR={\"address\": \"0x25dd2659a1430cdbd678615c7409164ae486c146\",\"blockNumber\": 10452223}\nBADGE_TCRS=[{\"address\": \"0xd58bdd286e8155b6223e2a62932ae3e0a9a75759\",\"blockNumber\": 10452276},{\"address\": \"0x78895ec026aeff2db73bc30e623c39e1c69b1386\",\"blockNumber\": 10708158}]\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkleros%2Faction-callback-bots","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkleros%2Faction-callback-bots","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkleros%2Faction-callback-bots/lists"}