-
Notifications
You must be signed in to change notification settings - Fork 409
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sendTx, estimateGas and simulate now all accept
wallet
OR account
- Loading branch information
Showing
9 changed files
with
178 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { describe, test, expect } from "vitest"; | ||
import { roundUpGas } from "./op-gas-fee-reducer.js"; | ||
import { hexToBigInt, numberToHex } from "viem"; | ||
|
||
describe("opGasFeeReducer", () => { | ||
test("should turn '0x3F1234' into '0x400000'", () => { | ||
const result = roundUpGas(hexToBigInt("0x3F1234")); | ||
expect(numberToHex(result)).toBe("0x400000"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/** | ||
* Via: https://twitter.com/0xjustadev/status/1758973668011434062 | ||
* | ||
* Increases the gas fee value to the nearest power of 2. | ||
* If the value is already a power of 2 or 0, it returns the value as is. | ||
* Otherwise, it finds the highest power of 2 that is bigger than the given value. | ||
* @param value - The gas fee value to be "rounded up". | ||
* @returns The *increased* gas value which will result in a lower L1 gas fee, overall reducing the gas fee. | ||
* @internal | ||
*/ | ||
export function roundUpGas(value: bigint): bigint { | ||
if (value === 0n || (value & (value - 1n)) === 0n) { | ||
return value; | ||
} | ||
|
||
// Find the highest set bit by shifting until the value is 0. | ||
let highestBit = 1n; | ||
while (value > 0n) { | ||
value >>= 1n; | ||
highestBit <<= 1n; | ||
} | ||
|
||
return highestBit; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters