-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This PR introduces a more sophisticated fine mechanism. The bundle of drafts is constructed as a multisend then a gas estimation is performed. The total transaction cost is then estimated as txCost = gasEstimation * min(baseFeePerGas + maxPriorityFeePerGas, maxFeePerGas) The fine amount is then max((txCost * 2) / drafts.length, MIN_FINE); where txCost * 2 represents the estimation of the bundle of both (drafts & fines), division by the number of drafts distributed the fine equally among the accounts being drafted. So this fineAmount says, the fine is MIN_FINE unless the transaction cost for execution winds up being more.
- Loading branch information
Showing
5 changed files
with
110 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,22 @@ | ||
# Dune Details | ||
BILLING_QUERY=3630322 | ||
FEE_QUERY=3605385 | ||
PAYMENT_QUERY=3742749 | ||
BOND_MAP="('0xa489faf6e337d997b8a23e2b6f3a8880b1b61e19', '0xfd39bc23d356a762cf80f60b7bc8d2a4b9bcfe67')" | ||
|
||
# Node Details | ||
## Testnet | ||
RPC_URL=https://rpc.ankr.com/eth_sepolia | ||
BILLING_CONTRACT_ADDRESS=0xF1436859a0F04A827b79F8c92736F6331ebB64A1 | ||
|
||
## Mainnet | ||
# RPC_URL=https://rpc.ankr.com/eth | ||
# BILLING_CONTRACT_ADDRESS=0x08Cd77fEB3fB28CC1606A91E0Ea2f5e3EABa1A9a | ||
|
||
# Billing Config | ||
BILLING_QUERY=3630322 | ||
FEE_QUERY=3605385 | ||
|
||
# Drafting Config | ||
ROLE_KEY= | ||
FINE_FEE=0 | ||
## This is $3.50 with ETH at $3500 | ||
FINE_MIN=0.001 | ||
PAYMENT_QUERY=3742749 | ||
BOND_MAP="('0xa489faf6e337d997b8a23e2b6f3a8880b1b61e19', '0xfd39bc23d356a762cf80f60b7bc8d2a4b9bcfe67')" | ||
|
||
# Secrets | ||
# Secrets: Required for both Billing & Drafting | ||
DUNE_API_KEY= | ||
# Required for Billing & Drafting | ||
BILLER_PRIVATE_KEY= |
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,36 @@ | ||
import { ethers } from "ethers"; | ||
|
||
export async function getTxCostForGas( | ||
provider: ethers.JsonRpcProvider, | ||
gasEstimate: bigint, | ||
): Promise<bigint> { | ||
const [{ maxPriorityFeePerGas, maxFeePerGas }, latestBlock] = | ||
await Promise.all([provider.getFeeData(), provider.getBlock("latest")]); | ||
if (!maxPriorityFeePerGas || !maxFeePerGas) { | ||
throw new Error("no gas fee data"); | ||
} | ||
const baseFeePerGas = latestBlock!.baseFeePerGas; | ||
if (!baseFeePerGas) { | ||
throw new Error("No base fee data"); | ||
} | ||
const effectiveGasPrice = minBigInt( | ||
baseFeePerGas + maxPriorityFeePerGas, | ||
maxFeePerGas, | ||
); | ||
|
||
return gasEstimate * effectiveGasPrice; | ||
} | ||
|
||
export function minBigInt(a: bigint, b: bigint): bigint { | ||
if (a < b) { | ||
return a; | ||
} | ||
return b; | ||
} | ||
|
||
export function maxBigInt(a: bigint, b: bigint): bigint { | ||
if (a > b) { | ||
return a; | ||
} | ||
return b; | ||
} |
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