├── .github └── workflows │ ├── main.yml │ └── size.yml ├── .gitignore ├── .prettierrc.json ├── CHANGELOG.md ├── INTERFACES.md ├── README.md ├── TSDOCS.md ├── package-lock.json ├── package.json ├── src └── index.ts ├── test └── lib.test.ts └── tsconfig.json /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | # GitHub Nodejs CI 2 | name: CI 3 | 4 | on: [push, pull_request] 5 | 6 | jobs: 7 | build: 8 | runs-on: ubuntu-latest 9 | 10 | strategy: 11 | matrix: 12 | node-version: ['14.x'] 13 | 14 | steps: 15 | - uses: actions/checkout@v2 16 | - name: Use Node.js ${{ matrix.node-version }} 17 | uses: actions/setup-node@v2 18 | with: 19 | node-version: ${{ matrix.node-version }} 20 | check-latest: true 21 | - name: npm install, build, and test 22 | run: | 23 | npm install 24 | npm run build 25 | env: 26 | CI: true 27 | -------------------------------------------------------------------------------- /.github/workflows/size.yml: -------------------------------------------------------------------------------- 1 | name: size 2 | on: [pull_request] 3 | jobs: 4 | size: 5 | runs-on: ubuntu-latest 6 | env: 7 | CI_JOB_NUMBER: 1 8 | steps: 9 | - uses: actions/checkout@v1 10 | - uses: andresz1/size-limit-action@v1 11 | with: 12 | github_token: ${{ secrets.GITHUB_TOKEN }} 13 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.log 2 | .DS_Store 3 | node_modules 4 | dist 5 | *.tgz 6 | *.tar.gz 7 | build/ 8 | -------------------------------------------------------------------------------- /.prettierrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json.schemastore.org/prettierrc", 3 | "arrowParens": "always", 4 | "bracketSpacing": true, 5 | "jsxBracketSameLine": false, 6 | "jsxSingleQuote": false, 7 | "printWidth": 80, 8 | "proseWrap": "always", 9 | "quoteProps": "as-needed", 10 | "semi": true, 11 | "singleQuote": true, 12 | "tabWidth": 2, 13 | "trailingComma": "all", 14 | "useTabs": false 15 | } 16 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. 4 | 5 | ### 0.1.1 (2021-04-12) 6 | 7 | 8 | ### Features 9 | 10 | * **release:** v0.1.0 ([288e31d](https://github.com/sambacha/libmev/commit/288e31d394006ec648467ac20d2bdab97267593d)) 11 | 12 | 13 | ### Bug Fixes 14 | 15 | * **lint:** use external configs ([b866944](https://github.com/sambacha/libmev/commit/b866944d2729fe751b79461e267ecfbbed34fe4e)) 16 | * **package:** postinstall ([cd0dbf2](https://github.com/sambacha/libmev/commit/cd0dbf26c2f99bc3338175d4ee55e3afa3c9973d)) 17 | -------------------------------------------------------------------------------- /INTERFACES.md: -------------------------------------------------------------------------------- 1 | [libmev](../README.md) / [Exports](../modules.md) / FlashbotsBundleRawTransaction 2 | 3 | # Interface: FlashbotsBundleRawTransaction 4 | 5 | ## Table of contents 6 | 7 | ### Properties 8 | 9 | - [signedTransaction](flashbotsbundlerawtransaction.md#signedtransaction) 10 | 11 | ## Properties 12 | 13 | ### signedTransaction 14 | 15 | • **signedTransaction**: *string* 16 | 17 | Defined in: [src/index.ts:21](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L21) 18 | [libmev](../README.md) / [Exports](../modules.md) / FlashbotsBundleTransaction 19 | 20 | # Interface: FlashbotsBundleTransaction 21 | 22 | ## Table of contents 23 | 24 | ### Properties 25 | 26 | - [signer](flashbotsbundletransaction.md#signer) 27 | - [transaction](flashbotsbundletransaction.md#transaction) 28 | 29 | ## Properties 30 | 31 | ### signer 32 | 33 | • **signer**: *Signer* 34 | 35 | Defined in: [src/index.ts:26](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L26) 36 | 37 | ___ 38 | 39 | ### transaction 40 | 41 | • **transaction**: TransactionRequest 42 | 43 | Defined in: [src/index.ts:25](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L25) 44 | [libmev](../README.md) / [Exports](../modules.md) / FlashbotsOptions 45 | 46 | # Interface: FlashbotsOptions 47 | 48 | ## Table of contents 49 | 50 | ### Properties 51 | 52 | - [maxTimestamp](flashbotsoptions.md#maxtimestamp) 53 | - [minTimestamp](flashbotsoptions.md#mintimestamp) 54 | 55 | ## Properties 56 | 57 | ### maxTimestamp 58 | 59 | • `Optional` **maxTimestamp**: *number* 60 | 61 | Defined in: [src/index.ts:31](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L31) 62 | 63 | ___ 64 | 65 | ### minTimestamp 66 | 67 | • `Optional` **minTimestamp**: *number* 68 | 69 | Defined in: [src/index.ts:30](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L30) 70 | [libmev](../README.md) / [Exports](../modules.md) / FlashbotsTransactionResponse 71 | 72 | # Interface: FlashbotsTransactionResponse 73 | 74 | ## Table of contents 75 | 76 | ### Properties 77 | 78 | - [bundleTransactions](flashbotstransactionresponse.md#bundletransactions) 79 | - [receipts](flashbotstransactionresponse.md#receipts) 80 | - [simulate](flashbotstransactionresponse.md#simulate) 81 | - [wait](flashbotstransactionresponse.md#wait) 82 | 83 | ## Properties 84 | 85 | ### bundleTransactions 86 | 87 | • **bundleTransactions**: [*TransactionAccountNonce*](transactionaccountnonce.md)[] 88 | 89 | Defined in: [src/index.ts:42](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L42) 90 | 91 | ___ 92 | 93 | ### receipts 94 | 95 | • **receipts**: () => *Promise* 96 | 97 | #### Type declaration: 98 | 99 | ▸ (): *Promise* 100 | 101 | **Returns:** *Promise* 102 | 103 | Defined in: [src/index.ts:45](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L45) 104 | 105 | Defined in: [src/index.ts:45](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L45) 106 | 107 | ___ 108 | 109 | ### simulate 110 | 111 | • **simulate**: () => *Promise*<[*SimulationResponse*](../modules.md#simulationresponse)\> 112 | 113 | #### Type declaration: 114 | 115 | ▸ (): *Promise*<[*SimulationResponse*](../modules.md#simulationresponse)\> 116 | 117 | **Returns:** *Promise*<[*SimulationResponse*](../modules.md#simulationresponse)\> 118 | 119 | Defined in: [src/index.ts:44](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L44) 120 | 121 | Defined in: [src/index.ts:44](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L44) 122 | 123 | ___ 124 | 125 | ### wait 126 | 127 | • **wait**: () => *Promise*<[*FlashbotsBundleResolution*](../enums/flashbotsbundleresolution.md)\> 128 | 129 | #### Type declaration: 130 | 131 | ▸ (): *Promise*<[*FlashbotsBundleResolution*](../enums/flashbotsbundleresolution.md)\> 132 | 133 | **Returns:** *Promise*<[*FlashbotsBundleResolution*](../enums/flashbotsbundleresolution.md)\> 134 | 135 | Defined in: [src/index.ts:43](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L43) 136 | 137 | Defined in: [src/index.ts:43](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L43) 138 | [libmev](../README.md) / [Exports](../modules.md) / GetUserStatsResponseSuccess 139 | 140 | # Interface: GetUserStatsResponseSuccess 141 | 142 | ## Table of contents 143 | 144 | ### Properties 145 | 146 | - [avg\_gas\_price\_gwei](getuserstatsresponsesuccess.md#avg_gas_price_gwei) 147 | - [avg\_gas\_price\_gwei\_last\_5m](getuserstatsresponsesuccess.md#avg_gas_price_gwei_last_5m) 148 | - [avg\_gas\_price\_gwei\_last\_7d](getuserstatsresponsesuccess.md#avg_gas_price_gwei_last_7d) 149 | - [avg\_gas\_price\_gwei\_last\_numberd](getuserstatsresponsesuccess.md#avg_gas_price_gwei_last_numberd) 150 | - [avg\_gas\_price\_gwei\_last\_numberh](getuserstatsresponsesuccess.md#avg_gas_price_gwei_last_numberh) 151 | - [blocks\_won\_last\_5m](getuserstatsresponsesuccess.md#blocks_won_last_5m) 152 | - [blocks\_won\_last\_7d](getuserstatsresponsesuccess.md#blocks_won_last_7d) 153 | - [blocks\_won\_last\_numberd](getuserstatsresponsesuccess.md#blocks_won_last_numberd) 154 | - [blocks\_won\_last\_numberh](getuserstatsresponsesuccess.md#blocks_won_last_numberh) 155 | - [blocks\_won\_total](getuserstatsresponsesuccess.md#blocks_won_total) 156 | - [bundles\_error\_5m](getuserstatsresponsesuccess.md#bundles_error_5m) 157 | - [bundles\_error\_7d](getuserstatsresponsesuccess.md#bundles_error_7d) 158 | - [bundles\_error\_numberd](getuserstatsresponsesuccess.md#bundles_error_numberd) 159 | - [bundles\_error\_numberh](getuserstatsresponsesuccess.md#bundles_error_numberh) 160 | - [bundles\_error\_total](getuserstatsresponsesuccess.md#bundles_error_total) 161 | - [bundles\_submitted\_last\_5m](getuserstatsresponsesuccess.md#bundles_submitted_last_5m) 162 | - [bundles\_submitted\_last\_7d](getuserstatsresponsesuccess.md#bundles_submitted_last_7d) 163 | - [bundles\_submitted\_last\_numberd](getuserstatsresponsesuccess.md#bundles_submitted_last_numberd) 164 | - [bundles\_submitted\_last\_numberh](getuserstatsresponsesuccess.md#bundles_submitted_last_numberh) 165 | - [bundles\_submitted\_total](getuserstatsresponsesuccess.md#bundles_submitted_total) 166 | - [signing\_address](getuserstatsresponsesuccess.md#signing_address) 167 | 168 | ## Properties 169 | 170 | ### avg\_gas\_price\_gwei 171 | 172 | • **avg\_gas\_price\_gwei**: *number* 173 | 174 | Defined in: [src/index.ts:89](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L89) 175 | 176 | ___ 177 | 178 | ### avg\_gas\_price\_gwei\_last\_5m 179 | 180 | • **avg\_gas\_price\_gwei\_last\_5m**: *number* 181 | 182 | Defined in: [src/index.ts:105](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L105) 183 | 184 | ___ 185 | 186 | ### avg\_gas\_price\_gwei\_last\_7d 187 | 188 | • **avg\_gas\_price\_gwei\_last\_7d**: *number* 189 | 190 | Defined in: [src/index.ts:93](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L93) 191 | 192 | ___ 193 | 194 | ### avg\_gas\_price\_gwei\_last\_numberd 195 | 196 | • **avg\_gas\_price\_gwei\_last\_numberd**: *number* 197 | 198 | Defined in: [src/index.ts:97](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L97) 199 | 200 | ___ 201 | 202 | ### avg\_gas\_price\_gwei\_last\_numberh 203 | 204 | • **avg\_gas\_price\_gwei\_last\_numberh**: *number* 205 | 206 | Defined in: [src/index.ts:101](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L101) 207 | 208 | ___ 209 | 210 | ### blocks\_won\_last\_5m 211 | 212 | • **blocks\_won\_last\_5m**: *number* 213 | 214 | Defined in: [src/index.ts:102](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L102) 215 | 216 | ___ 217 | 218 | ### blocks\_won\_last\_7d 219 | 220 | • **blocks\_won\_last\_7d**: *number* 221 | 222 | Defined in: [src/index.ts:90](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L90) 223 | 224 | ___ 225 | 226 | ### blocks\_won\_last\_numberd 227 | 228 | • **blocks\_won\_last\_numberd**: *number* 229 | 230 | Defined in: [src/index.ts:94](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L94) 231 | 232 | ___ 233 | 234 | ### blocks\_won\_last\_numberh 235 | 236 | • **blocks\_won\_last\_numberh**: *number* 237 | 238 | Defined in: [src/index.ts:98](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L98) 239 | 240 | ___ 241 | 242 | ### blocks\_won\_total 243 | 244 | • **blocks\_won\_total**: *number* 245 | 246 | Defined in: [src/index.ts:86](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L86) 247 | 248 | ___ 249 | 250 | ### bundles\_error\_5m 251 | 252 | • **bundles\_error\_5m**: *number* 253 | 254 | Defined in: [src/index.ts:104](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L104) 255 | 256 | ___ 257 | 258 | ### bundles\_error\_7d 259 | 260 | • **bundles\_error\_7d**: *number* 261 | 262 | Defined in: [src/index.ts:92](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L92) 263 | 264 | ___ 265 | 266 | ### bundles\_error\_numberd 267 | 268 | • **bundles\_error\_numberd**: *number* 269 | 270 | Defined in: [src/index.ts:96](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L96) 271 | 272 | ___ 273 | 274 | ### bundles\_error\_numberh 275 | 276 | • **bundles\_error\_numberh**: *number* 277 | 278 | Defined in: [src/index.ts:100](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L100) 279 | 280 | ___ 281 | 282 | ### bundles\_error\_total 283 | 284 | • **bundles\_error\_total**: *number* 285 | 286 | Defined in: [src/index.ts:88](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L88) 287 | 288 | ___ 289 | 290 | ### bundles\_submitted\_last\_5m 291 | 292 | • **bundles\_submitted\_last\_5m**: *number* 293 | 294 | Defined in: [src/index.ts:103](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L103) 295 | 296 | ___ 297 | 298 | ### bundles\_submitted\_last\_7d 299 | 300 | • **bundles\_submitted\_last\_7d**: *number* 301 | 302 | Defined in: [src/index.ts:91](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L91) 303 | 304 | ___ 305 | 306 | ### bundles\_submitted\_last\_numberd 307 | 308 | • **bundles\_submitted\_last\_numberd**: *number* 309 | 310 | Defined in: [src/index.ts:95](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L95) 311 | 312 | ___ 313 | 314 | ### bundles\_submitted\_last\_numberh 315 | 316 | • **bundles\_submitted\_last\_numberh**: *number* 317 | 318 | Defined in: [src/index.ts:99](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L99) 319 | 320 | ___ 321 | 322 | ### bundles\_submitted\_total 323 | 324 | • **bundles\_submitted\_total**: *number* 325 | 326 | Defined in: [src/index.ts:87](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L87) 327 | 328 | ___ 329 | 330 | ### signing\_address 331 | 332 | • **signing\_address**: *string* 333 | 334 | Defined in: [src/index.ts:85](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L85) 335 | [libmev](../README.md) / [Exports](../modules.md) / RelayResponseError 336 | 337 | # Interface: RelayResponseError 338 | 339 | ## Table of contents 340 | 341 | ### Properties 342 | 343 | - [error](relayresponseerror.md#error) 344 | 345 | ## Properties 346 | 347 | ### error 348 | 349 | • **error**: *object* 350 | 351 | #### Type declaration: 352 | 353 | Name | Type | 354 | :------ | :------ | 355 | `code` | *number* | 356 | `message` | *string* | 357 | 358 | Defined in: [src/index.ts:68](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L68) 359 | [libmev](../README.md) / [Exports](../modules.md) / SimulationResponseSuccess 360 | 361 | # Interface: SimulationResponseSuccess 362 | 363 | ## Table of contents 364 | 365 | ### Properties 366 | 367 | - [bundleHash](simulationresponsesuccess.md#bundlehash) 368 | - [coinbaseDiff](simulationresponsesuccess.md#coinbasediff) 369 | - [firstRevert](simulationresponsesuccess.md#firstrevert) 370 | - [results](simulationresponsesuccess.md#results) 371 | - [totalGasUsed](simulationresponsesuccess.md#totalgasused) 372 | 373 | ## Properties 374 | 375 | ### bundleHash 376 | 377 | • **bundleHash**: *string* 378 | 379 | Defined in: [src/index.ts:75](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L75) 380 | 381 | ___ 382 | 383 | ### coinbaseDiff 384 | 385 | • **coinbaseDiff**: *BigNumber* 386 | 387 | Defined in: [src/index.ts:76](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L76) 388 | 389 | ___ 390 | 391 | ### firstRevert 392 | 393 | • `Optional` **firstRevert**: [*TransactionSimulation*](../modules.md#transactionsimulation) 394 | 395 | Defined in: [src/index.ts:79](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L79) 396 | 397 | ___ 398 | 399 | ### results 400 | 401 | • **results**: [*TransactionSimulation*](../modules.md#transactionsimulation)[] 402 | 403 | Defined in: [src/index.ts:77](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L77) 404 | 405 | ___ 406 | 407 | ### totalGasUsed 408 | 409 | • **totalGasUsed**: *number* 410 | 411 | Defined in: [src/index.ts:78](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L78) 412 | [libmev](../README.md) / [Exports](../modules.md) / TransactionAccountNonce 413 | 414 | # Interface: TransactionAccountNonce 415 | 416 | ## Table of contents 417 | 418 | ### Properties 419 | 420 | - [account](transactionaccountnonce.md#account) 421 | - [hash](transactionaccountnonce.md#hash) 422 | - [nonce](transactionaccountnonce.md#nonce) 423 | - [signedTransaction](transactionaccountnonce.md#signedtransaction) 424 | 425 | ## Properties 426 | 427 | ### account 428 | 429 | • **account**: *string* 430 | 431 | Defined in: [src/index.ts:37](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L37) 432 | 433 | ___ 434 | 435 | ### hash 436 | 437 | • **hash**: *string* 438 | 439 | Defined in: [src/index.ts:35](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L35) 440 | 441 | ___ 442 | 443 | ### nonce 444 | 445 | • **nonce**: *number* 446 | 447 | Defined in: [src/index.ts:38](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L38) 448 | 449 | ___ 450 | 451 | ### signedTransaction 452 | 453 | • **signedTransaction**: *string* 454 | 455 | Defined in: [src/index.ts:36](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L36) 456 | [libmev](../README.md) / [Exports](../modules.md) / TransactionSimulationBase 457 | 458 | # Interface: TransactionSimulationBase 459 | 460 | ## Hierarchy 461 | 462 | * **TransactionSimulationBase** 463 | 464 | ↳ [*TransactionSimulationSuccess*](transactionsimulationsuccess.md) 465 | 466 | ↳ [*TransactionSimulationRevert*](transactionsimulationrevert.md) 467 | 468 | ## Table of contents 469 | 470 | ### Properties 471 | 472 | - [gasUsed](transactionsimulationbase.md#gasused) 473 | - [txHash](transactionsimulationbase.md#txhash) 474 | 475 | ## Properties 476 | 477 | ### gasUsed 478 | 479 | • **gasUsed**: *number* 480 | 481 | Defined in: [src/index.ts:50](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L50) 482 | 483 | ___ 484 | 485 | ### txHash 486 | 487 | • **txHash**: *string* 488 | 489 | Defined in: [src/index.ts:49](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L49) 490 | [libmev](../README.md) / [Exports](../modules.md) / TransactionSimulationRevert 491 | 492 | # Interface: TransactionSimulationRevert 493 | 494 | ## Hierarchy 495 | 496 | * [*TransactionSimulationBase*](transactionsimulationbase.md) 497 | 498 | ↳ **TransactionSimulationRevert** 499 | 500 | ## Table of contents 501 | 502 | ### Properties 503 | 504 | - [error](transactionsimulationrevert.md#error) 505 | - [gasUsed](transactionsimulationrevert.md#gasused) 506 | - [revert](transactionsimulationrevert.md#revert) 507 | - [txHash](transactionsimulationrevert.md#txhash) 508 | 509 | ## Properties 510 | 511 | ### error 512 | 513 | • **error**: *string* 514 | 515 | Defined in: [src/index.ts:59](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L59) 516 | 517 | ___ 518 | 519 | ### gasUsed 520 | 521 | • **gasUsed**: *number* 522 | 523 | Inherited from: [TransactionSimulationBase](transactionsimulationbase.md).[gasUsed](transactionsimulationbase.md#gasused) 524 | 525 | Defined in: [src/index.ts:50](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L50) 526 | 527 | ___ 528 | 529 | ### revert 530 | 531 | • **revert**: *string* 532 | 533 | Defined in: [src/index.ts:60](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L60) 534 | 535 | ___ 536 | 537 | ### txHash 538 | 539 | • **txHash**: *string* 540 | 541 | Inherited from: [TransactionSimulationBase](transactionsimulationbase.md).[txHash](transactionsimulationbase.md#txhash) 542 | 543 | Defined in: [src/index.ts:49](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L49) 544 | [libmev](../README.md) / [Exports](../modules.md) / TransactionSimulationSuccess 545 | 546 | # Interface: TransactionSimulationSuccess 547 | 548 | ## Hierarchy 549 | 550 | * [*TransactionSimulationBase*](transactionsimulationbase.md) 551 | 552 | ↳ **TransactionSimulationSuccess** 553 | 554 | ## Table of contents 555 | 556 | ### Properties 557 | 558 | - [gasUsed](transactionsimulationsuccess.md#gasused) 559 | - [txHash](transactionsimulationsuccess.md#txhash) 560 | - [value](transactionsimulationsuccess.md#value) 561 | 562 | ## Properties 563 | 564 | ### gasUsed 565 | 566 | • **gasUsed**: *number* 567 | 568 | Inherited from: [TransactionSimulationBase](transactionsimulationbase.md).[gasUsed](transactionsimulationbase.md#gasused) 569 | 570 | Defined in: [src/index.ts:50](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L50) 571 | 572 | ___ 573 | 574 | ### txHash 575 | 576 | • **txHash**: *string* 577 | 578 | Inherited from: [TransactionSimulationBase](transactionsimulationbase.md).[txHash](transactionsimulationbase.md#txhash) 579 | 580 | Defined in: [src/index.ts:49](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L49) 581 | 582 | ___ 583 | 584 | ### value 585 | 586 | • **value**: *string* 587 | 588 | Defined in: [src/index.ts:55](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L55) 589 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # [libmev](#) 2 | 3 | [![CI](https://github.com/sambacha/libmev/actions/workflows/main.yml/badge.svg)](https://github.com/sambacha/libmev/actions/workflows/main.yml) 4 | 5 | > miner extracted value library 6 | 7 | ### Overview 8 | 9 | > [libmev overview](https://sambacha.github.io/libmev/modules.html) 10 | 11 | 12 | ## Enumeration: FlashbotsBundleResolution 13 | 14 | ## Table of contents 15 | 16 | ### Enumeration members 17 | 18 | - [AccountNonceTooHigh](flashbotsbundleresolution.md#accountnoncetoohigh) 19 | - [BlockPassedWithoutInclusion](flashbotsbundleresolution.md#blockpassedwithoutinclusion) 20 | - [BundleIncluded](flashbotsbundleresolution.md#bundleincluded) 21 | 22 | ## Enumeration members 23 | 24 | ### AccountNonceTooHigh 25 | 26 | • **AccountNonceTooHigh**: = 2 27 | 28 | Defined in: [src/index.ts:17](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L17) 29 | 30 | ___ 31 | 32 | ### BlockPassedWithoutInclusion 33 | 34 | • **BlockPassedWithoutInclusion**: = 1 35 | 36 | Defined in: [src/index.ts:16](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L16) 37 | 38 | ___ 39 | 40 | ### BundleIncluded 41 | 42 | • **BundleIncluded**: = 0 43 | 44 | Defined in: [src/index.ts:15](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L15) 45 | [libmev](README.md) / Exports 46 | 47 | # libmev 48 | 49 | ## Table of contents 50 | 51 | ### Enumerations 52 | 53 | - [FlashbotsBundleResolution](enums/flashbotsbundleresolution.md) 54 | 55 | ### Classes 56 | 57 | - [FlashbotsBundleProvider](classes/flashbotsbundleprovider.md) 58 | 59 | ### Interfaces 60 | 61 | - [FlashbotsBundleRawTransaction](interfaces/flashbotsbundlerawtransaction.md) 62 | - [FlashbotsBundleTransaction](interfaces/flashbotsbundletransaction.md) 63 | - [FlashbotsOptions](interfaces/flashbotsoptions.md) 64 | - [FlashbotsTransactionResponse](interfaces/flashbotstransactionresponse.md) 65 | - [GetUserStatsResponseSuccess](interfaces/getuserstatsresponsesuccess.md) 66 | - [RelayResponseError](interfaces/relayresponseerror.md) 67 | - [SimulationResponseSuccess](interfaces/simulationresponsesuccess.md) 68 | - [TransactionAccountNonce](interfaces/transactionaccountnonce.md) 69 | - [TransactionSimulationBase](interfaces/transactionsimulationbase.md) 70 | - [TransactionSimulationRevert](interfaces/transactionsimulationrevert.md) 71 | - [TransactionSimulationSuccess](interfaces/transactionsimulationsuccess.md) 72 | 73 | ### Type aliases 74 | 75 | - [GetUserStatsResponse](modules.md#getuserstatsresponse) 76 | - [SimulationResponse](modules.md#simulationresponse) 77 | - [TransactionSimulation](modules.md#transactionsimulation) 78 | 79 | ### Variables 80 | 81 | - [DEFAULT\_FLASHBOTS\_RELAY](modules.md#default_flashbots_relay) 82 | 83 | ## Type aliases 84 | 85 | ### GetUserStatsResponse 86 | 87 | Ƭ **GetUserStatsResponse**: [*GetUserStatsResponseSuccess*](interfaces/getuserstatsresponsesuccess.md) \| [*RelayResponseError*](interfaces/relayresponseerror.md) 88 | 89 | Defined in: [src/index.ts:108](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L108) 90 | 91 | ___ 92 | 93 | ### SimulationResponse 94 | 95 | Ƭ **SimulationResponse**: [*SimulationResponseSuccess*](interfaces/simulationresponsesuccess.md) \| [*RelayResponseError*](interfaces/relayresponseerror.md) 96 | 97 | Defined in: [src/index.ts:82](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L82) 98 | 99 | ___ 100 | 101 | ### TransactionSimulation 102 | 103 | Ƭ **TransactionSimulation**: [*TransactionSimulationSuccess*](interfaces/transactionsimulationsuccess.md) \| [*TransactionSimulationRevert*](interfaces/transactionsimulationrevert.md) 104 | 105 | Defined in: [src/index.ts:63](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L63) 106 | 107 | ## Variables 108 | 109 | ### DEFAULT\_FLASHBOTS\_RELAY 110 | 111 | • `Const` **DEFAULT\_FLASHBOTS\_RELAY**: *https://relay.flashbots.net*= 'https://relay.flashbots.net' 112 | 113 | Defined in: [src/index.ts:12](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L12) 114 | [libmev](../README.md) / [Exports](../modules.md) / FlashbotsBundleRawTransaction 115 | 116 | # Interface: FlashbotsBundleRawTransaction 117 | 118 | ## Table of contents 119 | 120 | ### Properties 121 | 122 | - [signedTransaction](flashbotsbundlerawtransaction.md#signedtransaction) 123 | 124 | ## Properties 125 | 126 | ### signedTransaction 127 | 128 | • **signedTransaction**: *string* 129 | 130 | Defined in: [src/index.ts:21](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L21) 131 | [libmev](../README.md) / [Exports](../modules.md) / FlashbotsBundleTransaction 132 | 133 | # Interface: FlashbotsBundleTransaction 134 | 135 | ## Table of contents 136 | 137 | ### Properties 138 | 139 | - [signer](flashbotsbundletransaction.md#signer) 140 | - [transaction](flashbotsbundletransaction.md#transaction) 141 | 142 | ## Properties 143 | 144 | ### signer 145 | 146 | • **signer**: *Signer* 147 | 148 | Defined in: [src/index.ts:26](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L26) 149 | 150 | ___ 151 | 152 | ### transaction 153 | 154 | • **transaction**: TransactionRequest 155 | 156 | Defined in: [src/index.ts:25](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L25) 157 | [libmev](../README.md) / [Exports](../modules.md) / FlashbotsOptions 158 | 159 | ## Interface: FlashbotsOptions 160 | 161 | ## Table of contents 162 | 163 | ### Properties 164 | 165 | - [maxTimestamp](flashbotsoptions.md#maxtimestamp) 166 | - [minTimestamp](flashbotsoptions.md#mintimestamp) 167 | 168 | ## Properties 169 | 170 | ### maxTimestamp 171 | 172 | • `Optional` **maxTimestamp**: *number* 173 | 174 | Defined in: [src/index.ts:31](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L31) 175 | 176 | ___ 177 | 178 | ### minTimestamp 179 | 180 | • `Optional` **minTimestamp**: *number* 181 | 182 | Defined in: [src/index.ts:30](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L30) 183 | [libmev](../README.md) / [Exports](../modules.md) / FlashbotsTransactionResponse 184 | 185 | # Interface: FlashbotsTransactionResponse 186 | 187 | ## Table of contents 188 | 189 | ### Properties 190 | 191 | - [bundleTransactions](flashbotstransactionresponse.md#bundletransactions) 192 | - [receipts](flashbotstransactionresponse.md#receipts) 193 | - [simulate](flashbotstransactionresponse.md#simulate) 194 | - [wait](flashbotstransactionresponse.md#wait) 195 | 196 | ## Properties 197 | 198 | ### bundleTransactions 199 | 200 | • **bundleTransactions**: [*TransactionAccountNonce*](transactionaccountnonce.md)[] 201 | 202 | Defined in: [src/index.ts:42](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L42) 203 | 204 | ___ 205 | 206 | ### receipts 207 | 208 | • **receipts**: () => *Promise* 209 | 210 | #### Type declaration: 211 | 212 | ▸ (): *Promise* 213 | 214 | **Returns:** *Promise* 215 | 216 | Defined in: [src/index.ts:45](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L45) 217 | 218 | Defined in: [src/index.ts:45](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L45) 219 | 220 | ___ 221 | 222 | ### simulate 223 | 224 | • **simulate**: () => *Promise*<[*SimulationResponse*](../modules.md#simulationresponse)\> 225 | 226 | #### Type declaration: 227 | 228 | ▸ (): *Promise*<[*SimulationResponse*](../modules.md#simulationresponse)\> 229 | 230 | **Returns:** *Promise*<[*SimulationResponse*](../modules.md#simulationresponse)\> 231 | 232 | Defined in: [src/index.ts:44](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L44) 233 | 234 | Defined in: [src/index.ts:44](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L44) 235 | 236 | ___ 237 | 238 | ### wait 239 | 240 | • **wait**: () => *Promise*<[*FlashbotsBundleResolution*](../enums/flashbotsbundleresolution.md)\> 241 | 242 | #### Type declaration: 243 | 244 | ▸ (): *Promise*<[*FlashbotsBundleResolution*](../enums/flashbotsbundleresolution.md)\> 245 | 246 | **Returns:** *Promise*<[*FlashbotsBundleResolution*](../enums/flashbotsbundleresolution.md)\> 247 | 248 | Defined in: [src/index.ts:43](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L43) 249 | 250 | Defined in: [src/index.ts:43](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L43) 251 | [libmev](../README.md) / [Exports](../modules.md) / GetUserStatsResponseSuccess 252 | 253 | # Interface: GetUserStatsResponseSuccess 254 | 255 | ## Table of contents 256 | 257 | ### Properties 258 | 259 | - [avg\_gas\_price\_gwei](getuserstatsresponsesuccess.md#avg_gas_price_gwei) 260 | - [avg\_gas\_price\_gwei\_last\_5m](getuserstatsresponsesuccess.md#avg_gas_price_gwei_last_5m) 261 | - [avg\_gas\_price\_gwei\_last\_7d](getuserstatsresponsesuccess.md#avg_gas_price_gwei_last_7d) 262 | - [avg\_gas\_price\_gwei\_last\_numberd](getuserstatsresponsesuccess.md#avg_gas_price_gwei_last_numberd) 263 | - [avg\_gas\_price\_gwei\_last\_numberh](getuserstatsresponsesuccess.md#avg_gas_price_gwei_last_numberh) 264 | - [blocks\_won\_last\_5m](getuserstatsresponsesuccess.md#blocks_won_last_5m) 265 | - [blocks\_won\_last\_7d](getuserstatsresponsesuccess.md#blocks_won_last_7d) 266 | - [blocks\_won\_last\_numberd](getuserstatsresponsesuccess.md#blocks_won_last_numberd) 267 | - [blocks\_won\_last\_numberh](getuserstatsresponsesuccess.md#blocks_won_last_numberh) 268 | - [blocks\_won\_total](getuserstatsresponsesuccess.md#blocks_won_total) 269 | - [bundles\_error\_5m](getuserstatsresponsesuccess.md#bundles_error_5m) 270 | - [bundles\_error\_7d](getuserstatsresponsesuccess.md#bundles_error_7d) 271 | - [bundles\_error\_numberd](getuserstatsresponsesuccess.md#bundles_error_numberd) 272 | - [bundles\_error\_numberh](getuserstatsresponsesuccess.md#bundles_error_numberh) 273 | - [bundles\_error\_total](getuserstatsresponsesuccess.md#bundles_error_total) 274 | - [bundles\_submitted\_last\_5m](getuserstatsresponsesuccess.md#bundles_submitted_last_5m) 275 | - [bundles\_submitted\_last\_7d](getuserstatsresponsesuccess.md#bundles_submitted_last_7d) 276 | - [bundles\_submitted\_last\_numberd](getuserstatsresponsesuccess.md#bundles_submitted_last_numberd) 277 | - [bundles\_submitted\_last\_numberh](getuserstatsresponsesuccess.md#bundles_submitted_last_numberh) 278 | - [bundles\_submitted\_total](getuserstatsresponsesuccess.md#bundles_submitted_total) 279 | - [signing\_address](getuserstatsresponsesuccess.md#signing_address) 280 | 281 | ## Properties 282 | 283 | ### avg\_gas\_price\_gwei 284 | 285 | • **avg\_gas\_price\_gwei**: *number* 286 | 287 | Defined in: [src/index.ts:89](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L89) 288 | 289 | ___ 290 | 291 | ### avg\_gas\_price\_gwei\_last\_5m 292 | 293 | • **avg\_gas\_price\_gwei\_last\_5m**: *number* 294 | 295 | Defined in: [src/index.ts:105](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L105) 296 | 297 | ___ 298 | 299 | ### avg\_gas\_price\_gwei\_last\_7d 300 | 301 | • **avg\_gas\_price\_gwei\_last\_7d**: *number* 302 | 303 | Defined in: [src/index.ts:93](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L93) 304 | 305 | ___ 306 | 307 | ### avg\_gas\_price\_gwei\_last\_numberd 308 | 309 | • **avg\_gas\_price\_gwei\_last\_numberd**: *number* 310 | 311 | Defined in: [src/index.ts:97](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L97) 312 | 313 | ___ 314 | 315 | ### avg\_gas\_price\_gwei\_last\_numberh 316 | 317 | • **avg\_gas\_price\_gwei\_last\_numberh**: *number* 318 | 319 | Defined in: [src/index.ts:101](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L101) 320 | 321 | ___ 322 | 323 | ### blocks\_won\_last\_5m 324 | 325 | • **blocks\_won\_last\_5m**: *number* 326 | 327 | Defined in: [src/index.ts:102](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L102) 328 | 329 | ___ 330 | 331 | ### blocks\_won\_last\_7d 332 | 333 | • **blocks\_won\_last\_7d**: *number* 334 | 335 | Defined in: [src/index.ts:90](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L90) 336 | 337 | ___ 338 | 339 | ### blocks\_won\_last\_numberd 340 | 341 | • **blocks\_won\_last\_numberd**: *number* 342 | 343 | Defined in: [src/index.ts:94](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L94) 344 | 345 | ___ 346 | 347 | ### blocks\_won\_last\_numberh 348 | 349 | • **blocks\_won\_last\_numberh**: *number* 350 | 351 | Defined in: [src/index.ts:98](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L98) 352 | 353 | ___ 354 | 355 | ### blocks\_won\_total 356 | 357 | • **blocks\_won\_total**: *number* 358 | 359 | Defined in: [src/index.ts:86](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L86) 360 | 361 | ___ 362 | 363 | ### bundles\_error\_5m 364 | 365 | • **bundles\_error\_5m**: *number* 366 | 367 | Defined in: [src/index.ts:104](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L104) 368 | 369 | ___ 370 | 371 | ### bundles\_error\_7d 372 | 373 | • **bundles\_error\_7d**: *number* 374 | 375 | Defined in: [src/index.ts:92](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L92) 376 | 377 | ___ 378 | 379 | ### bundles\_error\_numberd 380 | 381 | • **bundles\_error\_numberd**: *number* 382 | 383 | Defined in: [src/index.ts:96](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L96) 384 | 385 | ___ 386 | 387 | ### bundles\_error\_numberh 388 | 389 | • **bundles\_error\_numberh**: *number* 390 | 391 | Defined in: [src/index.ts:100](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L100) 392 | 393 | ___ 394 | 395 | ### bundles\_error\_total 396 | 397 | • **bundles\_error\_total**: *number* 398 | 399 | Defined in: [src/index.ts:88](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L88) 400 | 401 | ___ 402 | 403 | ### bundles\_submitted\_last\_5m 404 | 405 | • **bundles\_submitted\_last\_5m**: *number* 406 | 407 | Defined in: [src/index.ts:103](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L103) 408 | 409 | ___ 410 | 411 | ### bundles\_submitted\_last\_7d 412 | 413 | • **bundles\_submitted\_last\_7d**: *number* 414 | 415 | Defined in: [src/index.ts:91](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L91) 416 | 417 | ___ 418 | 419 | ### bundles\_submitted\_last\_numberd 420 | 421 | • **bundles\_submitted\_last\_numberd**: *number* 422 | 423 | Defined in: [src/index.ts:95](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L95) 424 | 425 | ___ 426 | 427 | ### bundles\_submitted\_last\_numberh 428 | 429 | • **bundles\_submitted\_last\_numberh**: *number* 430 | 431 | Defined in: [src/index.ts:99](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L99) 432 | 433 | ___ 434 | 435 | ### bundles\_submitted\_total 436 | 437 | • **bundles\_submitted\_total**: *number* 438 | 439 | Defined in: [src/index.ts:87](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L87) 440 | 441 | ___ 442 | 443 | ### signing\_address 444 | 445 | • **signing\_address**: *string* 446 | 447 | Defined in: [src/index.ts:85](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L85) 448 | [libmev](../README.md) / [Exports](../modules.md) / RelayResponseError 449 | 450 | # Interface: RelayResponseError 451 | 452 | ## Table of contents 453 | 454 | ### Properties 455 | 456 | - [error](relayresponseerror.md#error) 457 | 458 | ## Properties 459 | 460 | ### error 461 | 462 | • **error**: *object* 463 | 464 | #### Type declaration: 465 | 466 | Name | Type | 467 | :------ | :------ | 468 | `code` | *number* | 469 | `message` | *string* | 470 | 471 | Defined in: [src/index.ts:68](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L68) 472 | [libmev](../README.md) / [Exports](../modules.md) / SimulationResponseSuccess 473 | 474 | ## Interface: SimulationResponseSuccess 475 | 476 | ## Table of contents 477 | 478 | ### Properties 479 | 480 | - [bundleHash](simulationresponsesuccess.md#bundlehash) 481 | - [coinbaseDiff](simulationresponsesuccess.md#coinbasediff) 482 | - [firstRevert](simulationresponsesuccess.md#firstrevert) 483 | - [results](simulationresponsesuccess.md#results) 484 | - [totalGasUsed](simulationresponsesuccess.md#totalgasused) 485 | 486 | ## Properties 487 | 488 | ### bundleHash 489 | 490 | • **bundleHash**: *string* 491 | 492 | Defined in: [src/index.ts:75](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L75) 493 | 494 | ___ 495 | 496 | ### coinbaseDiff 497 | 498 | • **coinbaseDiff**: *BigNumber* 499 | 500 | Defined in: [src/index.ts:76](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L76) 501 | 502 | ___ 503 | 504 | ### firstRevert 505 | 506 | • `Optional` **firstRevert**: [*TransactionSimulation*](../modules.md#transactionsimulation) 507 | 508 | Defined in: [src/index.ts:79](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L79) 509 | 510 | ___ 511 | 512 | ### results 513 | 514 | • **results**: [*TransactionSimulation*](../modules.md#transactionsimulation)[] 515 | 516 | Defined in: [src/index.ts:77](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L77) 517 | 518 | ___ 519 | 520 | ### totalGasUsed 521 | 522 | • **totalGasUsed**: *number* 523 | 524 | Defined in: [src/index.ts:78](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L78) 525 | [libmev](../README.md) / [Exports](../modules.md) / TransactionAccountNonce 526 | 527 | # Interface: TransactionAccountNonce 528 | 529 | ## Table of contents 530 | 531 | ### Properties 532 | 533 | - [account](transactionaccountnonce.md#account) 534 | - [hash](transactionaccountnonce.md#hash) 535 | - [nonce](transactionaccountnonce.md#nonce) 536 | - [signedTransaction](transactionaccountnonce.md#signedtransaction) 537 | 538 | ## Properties 539 | 540 | ### account 541 | 542 | • **account**: *string* 543 | 544 | Defined in: [src/index.ts:37](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L37) 545 | 546 | ___ 547 | 548 | ### hash 549 | 550 | • **hash**: *string* 551 | 552 | Defined in: [src/index.ts:35](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L35) 553 | 554 | ___ 555 | 556 | ### nonce 557 | 558 | • **nonce**: *number* 559 | 560 | Defined in: [src/index.ts:38](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L38) 561 | 562 | ___ 563 | 564 | ### signedTransaction 565 | 566 | • **signedTransaction**: *string* 567 | 568 | Defined in: [src/index.ts:36](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L36) 569 | [libmev](../README.md) / [Exports](../modules.md) / TransactionSimulationBase 570 | 571 | # Interface: TransactionSimulationBase 572 | 573 | ## Hierarchy 574 | 575 | * **TransactionSimulationBase** 576 | 577 | ↳ [*TransactionSimulationSuccess*](transactionsimulationsuccess.md) 578 | 579 | ↳ [*TransactionSimulationRevert*](transactionsimulationrevert.md) 580 | 581 | ## Table of contents 582 | 583 | ### Properties 584 | 585 | - [gasUsed](transactionsimulationbase.md#gasused) 586 | - [txHash](transactionsimulationbase.md#txhash) 587 | 588 | ## Properties 589 | 590 | ### gasUsed 591 | 592 | • **gasUsed**: *number* 593 | 594 | Defined in: [src/index.ts:50](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L50) 595 | 596 | ___ 597 | 598 | ### txHash 599 | 600 | • **txHash**: *string* 601 | 602 | Defined in: [src/index.ts:49](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L49) 603 | [libmev](../README.md) / [Exports](../modules.md) / TransactionSimulationRevert 604 | 605 | # Interface: TransactionSimulationRevert 606 | 607 | ## Hierarchy 608 | 609 | * [*TransactionSimulationBase*](transactionsimulationbase.md) 610 | 611 | ↳ **TransactionSimulationRevert** 612 | 613 | ## Table of contents 614 | 615 | ### Properties 616 | 617 | - [error](transactionsimulationrevert.md#error) 618 | - [gasUsed](transactionsimulationrevert.md#gasused) 619 | - [revert](transactionsimulationrevert.md#revert) 620 | - [txHash](transactionsimulationrevert.md#txhash) 621 | 622 | ## Properties 623 | 624 | ### error 625 | 626 | • **error**: *string* 627 | 628 | Defined in: [src/index.ts:59](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L59) 629 | 630 | ___ 631 | 632 | ### gasUsed 633 | 634 | • **gasUsed**: *number* 635 | 636 | Inherited from: [TransactionSimulationBase](transactionsimulationbase.md).[gasUsed](transactionsimulationbase.md#gasused) 637 | 638 | Defined in: [src/index.ts:50](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L50) 639 | 640 | ___ 641 | 642 | ### revert 643 | 644 | • **revert**: *string* 645 | 646 | Defined in: [src/index.ts:60](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L60) 647 | 648 | ___ 649 | 650 | ### txHash 651 | 652 | • **txHash**: *string* 653 | 654 | Inherited from: [TransactionSimulationBase](transactionsimulationbase.md).[txHash](transactionsimulationbase.md#txhash) 655 | 656 | Defined in: [src/index.ts:49](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L49) 657 | [libmev](../README.md) / [Exports](../modules.md) / TransactionSimulationSuccess 658 | 659 | # Interface: TransactionSimulationSuccess 660 | 661 | ## Hierarchy 662 | 663 | * [*TransactionSimulationBase*](transactionsimulationbase.md) 664 | 665 | ↳ **TransactionSimulationSuccess** 666 | 667 | ## Table of contents 668 | 669 | ### Properties 670 | 671 | - [gasUsed](transactionsimulationsuccess.md#gasused) 672 | - [txHash](transactionsimulationsuccess.md#txhash) 673 | - [value](transactionsimulationsuccess.md#value) 674 | 675 | ## Properties 676 | 677 | ### gasUsed 678 | 679 | • **gasUsed**: *number* 680 | 681 | Inherited from: [TransactionSimulationBase](transactionsimulationbase.md).[gasUsed](transactionsimulationbase.md#gasused) 682 | 683 | Defined in: [src/index.ts:50](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L50) 684 | 685 | ___ 686 | 687 | ### txHash 688 | 689 | • **txHash**: *string* 690 | 691 | Inherited from: [TransactionSimulationBase](transactionsimulationbase.md).[txHash](transactionsimulationbase.md#txhash) 692 | 693 | Defined in: [src/index.ts:49](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L49) 694 | 695 | ___ 696 | 697 | ### value 698 | 699 | • **value**: *string* 700 | 701 | Defined in: [src/index.ts:55](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L55) 702 | -------------------------------------------------------------------------------- /TSDOCS.md: -------------------------------------------------------------------------------- 1 | libmev / [Exports](modules.md) 2 | 3 | # [libmev](#) 4 | 5 | [![CI](https://github.com/sambacha/libmev/actions/workflows/main.yml/badge.svg)](https://github.com/sambacha/libmev/actions/workflows/main.yml) 6 | 7 | > miner extracted value library 8 | 9 | ### Overview 10 | 11 | > [libmev overview](https://sambacha.github.io/libmev/modules.html) 12 | 13 | ## License 14 | 15 | SPDX-License-Identifier: MIT AND SSPL-1.0 16 | [libmev](../README.md) / [Exports](../modules.md) / FlashbotsBundleResolution 17 | 18 | # Enumeration: FlashbotsBundleResolution 19 | 20 | ## Table of contents 21 | 22 | ### Enumeration members 23 | 24 | - [AccountNonceTooHigh](flashbotsbundleresolution.md#accountnoncetoohigh) 25 | - [BlockPassedWithoutInclusion](flashbotsbundleresolution.md#blockpassedwithoutinclusion) 26 | - [BundleIncluded](flashbotsbundleresolution.md#bundleincluded) 27 | 28 | ## Enumeration members 29 | 30 | ### AccountNonceTooHigh 31 | 32 | • **AccountNonceTooHigh**: = 2 33 | 34 | Defined in: [src/index.ts:17](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L17) 35 | 36 | ___ 37 | 38 | ### BlockPassedWithoutInclusion 39 | 40 | • **BlockPassedWithoutInclusion**: = 1 41 | 42 | Defined in: [src/index.ts:16](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L16) 43 | 44 | ___ 45 | 46 | ### BundleIncluded 47 | 48 | • **BundleIncluded**: = 0 49 | 50 | Defined in: [src/index.ts:15](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L15) 51 | [libmev](README.md) / Exports 52 | 53 | # libmev 54 | 55 | ## Table of contents 56 | 57 | ### Enumerations 58 | 59 | - [FlashbotsBundleResolution](enums/flashbotsbundleresolution.md) 60 | 61 | ### Classes 62 | 63 | - [FlashbotsBundleProvider](classes/flashbotsbundleprovider.md) 64 | 65 | ### Interfaces 66 | 67 | - [FlashbotsBundleRawTransaction](interfaces/flashbotsbundlerawtransaction.md) 68 | - [FlashbotsBundleTransaction](interfaces/flashbotsbundletransaction.md) 69 | - [FlashbotsOptions](interfaces/flashbotsoptions.md) 70 | - [FlashbotsTransactionResponse](interfaces/flashbotstransactionresponse.md) 71 | - [GetUserStatsResponseSuccess](interfaces/getuserstatsresponsesuccess.md) 72 | - [RelayResponseError](interfaces/relayresponseerror.md) 73 | - [SimulationResponseSuccess](interfaces/simulationresponsesuccess.md) 74 | - [TransactionAccountNonce](interfaces/transactionaccountnonce.md) 75 | - [TransactionSimulationBase](interfaces/transactionsimulationbase.md) 76 | - [TransactionSimulationRevert](interfaces/transactionsimulationrevert.md) 77 | - [TransactionSimulationSuccess](interfaces/transactionsimulationsuccess.md) 78 | 79 | ### Type aliases 80 | 81 | - [GetUserStatsResponse](modules.md#getuserstatsresponse) 82 | - [SimulationResponse](modules.md#simulationresponse) 83 | - [TransactionSimulation](modules.md#transactionsimulation) 84 | 85 | ### Variables 86 | 87 | - [DEFAULT\_FLASHBOTS\_RELAY](modules.md#default_flashbots_relay) 88 | 89 | ## Type aliases 90 | 91 | ### GetUserStatsResponse 92 | 93 | Ƭ **GetUserStatsResponse**: [*GetUserStatsResponseSuccess*](interfaces/getuserstatsresponsesuccess.md) \| [*RelayResponseError*](interfaces/relayresponseerror.md) 94 | 95 | Defined in: [src/index.ts:108](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L108) 96 | 97 | ___ 98 | 99 | ### SimulationResponse 100 | 101 | Ƭ **SimulationResponse**: [*SimulationResponseSuccess*](interfaces/simulationresponsesuccess.md) \| [*RelayResponseError*](interfaces/relayresponseerror.md) 102 | 103 | Defined in: [src/index.ts:82](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L82) 104 | 105 | ___ 106 | 107 | ### TransactionSimulation 108 | 109 | Ƭ **TransactionSimulation**: [*TransactionSimulationSuccess*](interfaces/transactionsimulationsuccess.md) \| [*TransactionSimulationRevert*](interfaces/transactionsimulationrevert.md) 110 | 111 | Defined in: [src/index.ts:63](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L63) 112 | 113 | ## Variables 114 | 115 | ### DEFAULT\_FLASHBOTS\_RELAY 116 | 117 | • `Const` **DEFAULT\_FLASHBOTS\_RELAY**: *https://relay.flashbots.net*= 'https://relay.flashbots.net' 118 | 119 | Defined in: [src/index.ts:12](https://github.com/sambacha/libmev/blob/cd0dbf2/src/index.ts#L12) 120 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.1.1", 3 | "license": "SEE LICENSE IN LICENSE", 4 | "main": "dist/index.js", 5 | "typings": "dist/index.d.ts", 6 | "files": [ 7 | "dist", 8 | "src" 9 | ], 10 | "engines": { 11 | "node": ">=10" 12 | }, 13 | "scripts": { 14 | "start": "tsdx watch", 15 | "build": "tsdx build", 16 | "test": "tsdx test", 17 | "lint": "tsdx lint", 18 | "prepare": "tsdx build", 19 | "postinstall": "npm install ethers", 20 | "size": "size-limit", 21 | "analyze": "size-limit --why", 22 | "docs": "npx typedoc src/index.ts" 23 | }, 24 | "husky": { 25 | "hooks": { 26 | "pre-commit": "tsdx lint" 27 | } 28 | }, 29 | "name": "libmev", 30 | "author": "SEE CONTRIBUTORS", 31 | "module": "dist/libmev.esm.js", 32 | "size-limit": [ 33 | { 34 | "path": "dist/libmev.cjs.production.min.js", 35 | "limit": "10 KB" 36 | }, 37 | { 38 | "path": "dist/libmev.esm.js", 39 | "limit": "30 KB" 40 | } 41 | ], 42 | "devDependencies": { 43 | "@size-limit/preset-small-lib": "^4.10.2", 44 | "husky": "^6.0.0", 45 | "size-limit": "^4.10.2", 46 | "tsdx": "^0.14.1", 47 | "tslib": "^2.2.0", 48 | "typedoc": "^0.20.35", 49 | "typedoc-neo-theme": "^1.1.0", 50 | "typescript": "^4.2.4" 51 | }, 52 | "dependencies": { 53 | "@ethersproject/abstract-provider": "^5.1.0", 54 | "@ethersproject/networks": "^5.1.0", 55 | "@ethersproject/providers": "^5.1.0", 56 | "@ethersproject/web": "^5.1.0" 57 | }, 58 | "peerDependencies": { 59 | "ethers": "^5.1.0" 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | import { 2 | BlockTag, 3 | TransactionReceipt, 4 | TransactionRequest, 5 | } from '@ethersproject/abstract-provider'; 6 | import { Networkish } from '@ethersproject/networks'; 7 | import { BaseProvider } from '@ethersproject/providers'; 8 | import { ConnectionInfo, fetchJson } from '@ethersproject/web'; 9 | import { BigNumber, ethers, providers, Signer } from 'ethers'; 10 | import { id } from 'ethers/lib/utils'; 11 | 12 | export const DEFAULT_FLASHBOTS_RELAY = 'https://relay.flashbots.net'; 13 | 14 | export enum FlashbotsBundleResolution { 15 | BundleIncluded, 16 | BlockPassedWithoutInclusion, 17 | AccountNonceTooHigh, 18 | } 19 | 20 | export interface FlashbotsBundleRawTransaction { 21 | signedTransaction: string; 22 | } 23 | 24 | export interface FlashbotsBundleTransaction { 25 | transaction: TransactionRequest; 26 | signer: Signer; 27 | } 28 | 29 | export interface FlashbotsOptions { 30 | minTimestamp?: number; 31 | maxTimestamp?: number; 32 | } 33 | 34 | export interface TransactionAccountNonce { 35 | hash: string; 36 | signedTransaction: string; 37 | account: string; 38 | nonce: number; 39 | } 40 | 41 | export interface FlashbotsTransactionResponse { 42 | bundleTransactions: Array; 43 | wait: () => Promise; 44 | simulate: () => Promise; 45 | receipts: () => Promise>; 46 | } 47 | 48 | export interface TransactionSimulationBase { 49 | txHash: string; 50 | gasUsed: number; 51 | } 52 | 53 | export interface TransactionSimulationSuccess 54 | extends TransactionSimulationBase { 55 | value: string; 56 | } 57 | 58 | export interface TransactionSimulationRevert extends TransactionSimulationBase { 59 | error: string; 60 | revert: string; 61 | } 62 | 63 | export type TransactionSimulation = 64 | | TransactionSimulationSuccess 65 | | TransactionSimulationRevert; 66 | 67 | export interface RelayResponseError { 68 | error: { 69 | message: string; 70 | code: number; 71 | }; 72 | } 73 | 74 | export interface SimulationResponseSuccess { 75 | bundleHash: string; 76 | coinbaseDiff: BigNumber; 77 | results: Array; 78 | totalGasUsed: number; 79 | firstRevert?: TransactionSimulation; 80 | } 81 | 82 | export type SimulationResponse = SimulationResponseSuccess | RelayResponseError; 83 | 84 | export interface GetUserStatsResponseSuccess { 85 | signing_address: string; 86 | blocks_won_total: number; 87 | bundles_submitted_total: number; 88 | bundles_error_total: number; 89 | avg_gas_price_gwei: number; 90 | blocks_won_last_7d: number; 91 | bundles_submitted_last_7d: number; 92 | bundles_error_7d: number; 93 | avg_gas_price_gwei_last_7d: number; 94 | blocks_won_last_numberd: number; 95 | bundles_submitted_last_numberd: number; 96 | bundles_error_numberd: number; 97 | avg_gas_price_gwei_last_numberd: number; 98 | blocks_won_last_numberh: number; 99 | bundles_submitted_last_numberh: number; 100 | bundles_error_numberh: number; 101 | avg_gas_price_gwei_last_numberh: number; 102 | blocks_won_last_5m: number; 103 | bundles_submitted_last_5m: number; 104 | bundles_error_5m: number; 105 | avg_gas_price_gwei_last_5m: number; 106 | } 107 | 108 | export type GetUserStatsResponse = 109 | | GetUserStatsResponseSuccess 110 | | RelayResponseError; 111 | 112 | type RpcParams = Array; 113 | 114 | const TIMEOUT_MS = 5 * 60 * 1000; 115 | 116 | export class FlashbotsBundleProvider extends providers.JsonRpcProvider { 117 | private genericProvider: BaseProvider; 118 | private authSigner: Signer; 119 | private connectionInfo: ConnectionInfo; 120 | 121 | constructor( 122 | genericProvider: BaseProvider, 123 | authSigner: Signer, 124 | connectionInfoOrUrl: ConnectionInfo, 125 | network: Networkish, 126 | ) { 127 | super(connectionInfoOrUrl, network); 128 | this.genericProvider = genericProvider; 129 | this.authSigner = authSigner; 130 | this.connectionInfo = connectionInfoOrUrl; 131 | } 132 | 133 | static async throttleCallback(): Promise { 134 | console.warn('Rate limited'); 135 | return false; 136 | } 137 | 138 | static async create( 139 | genericProvider: BaseProvider, 140 | authSigner: Signer, 141 | connectionInfoOrUrl?: ConnectionInfo | string, 142 | network?: Networkish, 143 | ): Promise { 144 | const connectionInfo: ConnectionInfo = 145 | typeof connectionInfoOrUrl === 'string' || 146 | typeof connectionInfoOrUrl === 'undefined' 147 | ? { 148 | url: connectionInfoOrUrl || DEFAULT_FLASHBOTS_RELAY, 149 | } 150 | : { 151 | ...connectionInfoOrUrl, 152 | }; 153 | if (connectionInfo.headers === undefined) connectionInfo.headers = {}; 154 | connectionInfo.throttleCallback = FlashbotsBundleProvider.throttleCallback; 155 | const networkish: Networkish = { 156 | chainId: 0, 157 | name: '', 158 | }; 159 | if (typeof network === 'string') { 160 | networkish.name = network; 161 | } else if (typeof network === 'number') { 162 | networkish.chainId = network; 163 | } else if (typeof network === 'object') { 164 | networkish.name = network.name; 165 | networkish.chainId = network.chainId; 166 | } 167 | 168 | if (networkish.chainId === 0) { 169 | networkish.chainId = (await genericProvider.getNetwork()).chainId; 170 | } 171 | 172 | return new FlashbotsBundleProvider( 173 | genericProvider, 174 | authSigner, 175 | connectionInfo, 176 | networkish, 177 | ); 178 | } 179 | 180 | public async sendRawBundle( 181 | signedBundledTransactions: Array, 182 | targetBlockNumber: number, 183 | opts?: FlashbotsOptions, 184 | ): Promise { 185 | const params = [ 186 | signedBundledTransactions, 187 | `0x${targetBlockNumber.toString(16)}`, 188 | opts?.minTimestamp || 0, 189 | opts?.maxTimestamp || 0, 190 | ]; 191 | const request = JSON.stringify( 192 | this.prepareBundleRequest('eth_sendBundle', params), 193 | ); 194 | await this.request(request); 195 | 196 | const bundleTransactions = signedBundledTransactions.map( 197 | (signedTransaction) => { 198 | const transactionDetails = ethers.utils.parseTransaction( 199 | signedTransaction, 200 | ); 201 | return { 202 | signedTransaction, 203 | hash: ethers.utils.keccak256(signedTransaction), 204 | account: transactionDetails.from || '0x0', 205 | nonce: transactionDetails.nonce, 206 | }; 207 | }, 208 | ); 209 | 210 | return { 211 | bundleTransactions, 212 | wait: () => this.wait(bundleTransactions, targetBlockNumber, TIMEOUT_MS), 213 | simulate: () => 214 | this.simulate( 215 | bundleTransactions.map((tx) => tx.signedTransaction), 216 | targetBlockNumber, 217 | undefined, 218 | opts?.minTimestamp, 219 | ), 220 | receipts: () => this.fetchReceipts(bundleTransactions), 221 | }; 222 | } 223 | 224 | public async sendBundle( 225 | bundledTransactions: Array< 226 | FlashbotsBundleTransaction | FlashbotsBundleRawTransaction 227 | >, 228 | targetBlockNumber: number, 229 | opts?: FlashbotsOptions, 230 | ): Promise { 231 | const signedTransactions = await this.signBundle(bundledTransactions); 232 | return this.sendRawBundle(signedTransactions, targetBlockNumber, opts); 233 | } 234 | 235 | public async signBundle( 236 | bundledTransactions: Array< 237 | FlashbotsBundleTransaction | FlashbotsBundleRawTransaction 238 | >, 239 | ): Promise> { 240 | const nonces: { [address: string]: BigNumber } = {}; 241 | const signedTransactions = new Array(); 242 | for (const tx of bundledTransactions) { 243 | if ('signedTransaction' in tx) { 244 | // in case someone is mixing pre-signed and signing transactions, decode to add to nonce object 245 | const transactionDetails = ethers.utils.parseTransaction( 246 | tx.signedTransaction, 247 | ); 248 | if (transactionDetails.from === undefined) 249 | throw new Error('Could not decode signed transaction'); 250 | nonces[transactionDetails.from] = BigNumber.from( 251 | transactionDetails.nonce + 1, 252 | ); 253 | signedTransactions.push(tx.signedTransaction); 254 | continue; 255 | } 256 | const transaction = { ...tx.transaction }; 257 | const address = await tx.signer.getAddress(); 258 | if (typeof transaction.nonce === 'string') throw new Error('Bad nonce'); 259 | const nonce = 260 | transaction.nonce !== undefined 261 | ? BigNumber.from(transaction.nonce) 262 | : nonces[address] || 263 | BigNumber.from( 264 | await this.genericProvider.getTransactionCount(address, 'latest'), 265 | ); 266 | nonces[address] = nonce.add(1); 267 | if (transaction.nonce === undefined) transaction.nonce = nonce; 268 | if (transaction.gasPrice === undefined) 269 | transaction.gasPrice = BigNumber.from(0); 270 | if (transaction.gasLimit === undefined) 271 | transaction.gasLimit = await tx.signer.estimateGas(transaction); // TODO: Add target block number and timestamp when supported by geth 272 | signedTransactions.push(await tx.signer.signTransaction(transaction)); 273 | } 274 | return signedTransactions; 275 | } 276 | 277 | private wait( 278 | transactionAccountNonces: Array, 279 | targetBlockNumber: number, 280 | timeout: number, 281 | ) { 282 | return new Promise((resolve, reject) => { 283 | let timer: NodeJS.Timer | null = null; 284 | let done = false; 285 | 286 | const minimumNonceByAccount = transactionAccountNonces.reduce( 287 | (acc, accountNonce) => { 288 | if ( 289 | accountNonce.nonce > 0 && 290 | (accountNonce.nonce || 0) < acc[accountNonce.account] 291 | ) { 292 | acc[accountNonce.account] = accountNonce.nonce; 293 | } 294 | acc[accountNonce.account] = accountNonce.nonce; 295 | return acc; 296 | }, 297 | {} as { [account: string]: number }, 298 | ); 299 | const handler = async (blockNumber: number) => { 300 | if (blockNumber < targetBlockNumber) { 301 | const noncesValid = await Promise.all( 302 | Object.entries(minimumNonceByAccount).map( 303 | async ([account, nonce]) => { 304 | const transactionCount = await this.genericProvider.getTransactionCount( 305 | account, 306 | ); 307 | return nonce >= transactionCount; 308 | }, 309 | ), 310 | ); 311 | const allNoncesValid = noncesValid.every(Boolean); 312 | if (allNoncesValid) return; 313 | // target block not yet reached, but nonce has become invalid 314 | resolve(FlashbotsBundleResolution.AccountNonceTooHigh); 315 | } else { 316 | const block = await this.genericProvider.getBlock(targetBlockNumber); 317 | // check bundle against block: 318 | const bundleIncluded = transactionAccountNonces.every( 319 | (transaction, i) => 320 | block.transactions[block.transactions.length - 1 - i] === 321 | transaction.hash, 322 | ); 323 | resolve( 324 | bundleIncluded 325 | ? FlashbotsBundleResolution.BundleIncluded 326 | : FlashbotsBundleResolution.BlockPassedWithoutInclusion, 327 | ); 328 | } 329 | 330 | if (timer) { 331 | clearTimeout(timer); 332 | } 333 | if (done) { 334 | return; 335 | } 336 | done = true; 337 | 338 | this.genericProvider.removeListener('block', handler); 339 | }; 340 | this.genericProvider.on('block', handler); 341 | 342 | if (typeof timeout === 'number' && timeout > 0) { 343 | timer = setTimeout(() => { 344 | if (done) { 345 | return; 346 | } 347 | timer = null; 348 | done = true; 349 | 350 | this.genericProvider.removeListener('block', handler); 351 | reject('Timed out'); 352 | }, timeout); 353 | if (timer.unref) { 354 | timer.unref(); 355 | } 356 | } 357 | }); 358 | } 359 | 360 | public async getUserStats(): Promise { 361 | const blockDetails = await this.genericProvider.getBlock('latest'); 362 | const evmBlockNumber = `0x${blockDetails.number.toString(16)}`; 363 | 364 | const params = [evmBlockNumber]; 365 | const request = JSON.stringify( 366 | this.prepareBundleRequest('flashbots_getUserStats', params), 367 | ); 368 | const response = await this.request(request); 369 | if (response.error !== undefined) { 370 | return { 371 | error: { 372 | message: response.error.message, 373 | code: response.error.code, 374 | }, 375 | }; 376 | } 377 | 378 | return response.result; 379 | } 380 | 381 | public async simulate( 382 | signedBundledTransactions: Array, 383 | blockTag: BlockTag, 384 | stateBlockTag?: BlockTag, 385 | blockTimestamp?: number, 386 | ): Promise { 387 | let evmBlockNumber: string; 388 | if (typeof blockTag === 'number') { 389 | evmBlockNumber = `0x${blockTag.toString(16)}`; 390 | } else { 391 | const blockTagDetails = await this.genericProvider.getBlock(blockTag); 392 | const blockDetails = 393 | blockTagDetails !== null 394 | ? blockTagDetails 395 | : await this.genericProvider.getBlock('latest'); 396 | evmBlockNumber = `0x${blockDetails.number.toString(16)}`; 397 | } 398 | 399 | let evmBlockStateNumber: string; 400 | if (typeof stateBlockTag === 'number') { 401 | evmBlockStateNumber = `0x${blockTag.toString(16)}`; 402 | } else if (!stateBlockTag) { 403 | evmBlockStateNumber = 'latest'; 404 | } else { 405 | evmBlockStateNumber = stateBlockTag; 406 | } 407 | 408 | const params: RpcParams = [ 409 | signedBundledTransactions, 410 | evmBlockNumber, 411 | evmBlockStateNumber, 412 | ]; 413 | if (blockTimestamp) { 414 | params.push(blockTimestamp); 415 | } 416 | const request = JSON.stringify( 417 | this.prepareBundleRequest('eth_callBundle', params), 418 | ); 419 | const response = await this.request(request); 420 | if (response.error !== undefined) { 421 | return { 422 | error: { 423 | message: response.error.message, 424 | code: response.error.code, 425 | }, 426 | }; 427 | } 428 | 429 | const callResult = response.result; 430 | return { 431 | bundleHash: callResult.bundleHash, 432 | coinbaseDiff: BigNumber.from(callResult.coinbaseDiff), 433 | results: callResult.results, 434 | totalGasUsed: callResult.results.reduce( 435 | (a: number, b: TransactionSimulation) => a + b.gasUsed, 436 | 0, 437 | ), 438 | firstRevert: callResult.results.find( 439 | (txSim: TransactionSimulation) => 'revert' in txSim, 440 | ), 441 | }; 442 | } 443 | 444 | private async request(request: string) { 445 | const connectionInfo = { ...this.connectionInfo }; 446 | connectionInfo.headers = { 447 | 'X-Flashbots-Signature': `${await this.authSigner.getAddress()}:${await this.authSigner.signMessage( 448 | id(request), 449 | )}`, 450 | ...this.connectionInfo.headers, 451 | }; 452 | return fetchJson(connectionInfo, request); 453 | } 454 | 455 | private async fetchReceipts( 456 | bundledTransactions: Array, 457 | ): Promise> { 458 | return Promise.all( 459 | bundledTransactions.map((bundledTransaction) => 460 | this.genericProvider.getTransactionReceipt(bundledTransaction.hash), 461 | ), 462 | ); 463 | } 464 | 465 | private prepareBundleRequest( 466 | method: 'eth_callBundle' | 'eth_sendBundle' | 'flashbots_getUserStats', 467 | params: RpcParams, 468 | ) { 469 | return { 470 | method: method, 471 | params: params, 472 | id: this._nextId++, 473 | jsonrpc: '2.0', 474 | }; 475 | } 476 | } 477 | -------------------------------------------------------------------------------- /test/lib.test.ts: -------------------------------------------------------------------------------- 1 | import { sum } from '../src'; 2 | 3 | describe('blah', () => { 4 | it('works', () => { 5 | expect(sum(1, 1)).toEqual(2); 6 | }); 7 | }); 8 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | // see https://www.typescriptlang.org/tsconfig to better understand tsconfigs 3 | "include": ["src", "types"], 4 | "compilerOptions": { 5 | "module": "esnext", 6 | "lib": ["dom", "esnext"], 7 | "importHelpers": true, 8 | // output .d.ts declaration files for consumers 9 | "declaration": true, 10 | // output .js.map sourcemap files for consumers 11 | "sourceMap": true, 12 | // match output dir to input dir. e.g. dist/index instead of dist/src/index 13 | "rootDir": "./src", 14 | // stricter type-checking for stronger correctness. Recommended by TS 15 | "strict": true, 16 | // linter checks for common issues 17 | "noImplicitReturns": true, 18 | "noFallthroughCasesInSwitch": true, 19 | // noUnused* overlap with @typescript-eslint/no-unused-vars, can disable if duplicative 20 | "noUnusedLocals": true, 21 | "noUnusedParameters": true, 22 | // use Node's module resolution algorithm, instead of the legacy TS one 23 | "moduleResolution": "node", 24 | // transpile JSX to React.createElement 25 | "jsx": "react", 26 | // interop between ESM and CJS modules. Recommended by TS 27 | "esModuleInterop": true, 28 | // significant perf increase by skipping checking .d.ts files, particularly those in node_modules. Recommended by TS 29 | "skipLibCheck": true, 30 | // error out if import and file system have a casing mismatch. Recommended by TS 31 | "forceConsistentCasingInFileNames": true, 32 | // `tsdx build` ignores this option, but it is commonly used when type-checking separately with `tsc` 33 | "noEmit": true, 34 | } 35 | } 36 | --------------------------------------------------------------------------------