@gvnrdao/dh-sdk 0.0.333 → 0.0.334
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/browser/dist/browser.js +1 -1
- package/dist/index.js +79 -18
- package/dist/index.mjs +84 -19
- package/dist/utils/chunks/eip1559-broadcast.utils.d.ts +57 -4
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -4264,11 +4264,11 @@ ${auth.clientId}`;
|
|
|
4264
4264
|
);
|
|
4265
4265
|
const prices = await Promise.race([fetchAll, timeoutPromise]);
|
|
4266
4266
|
const sorted = [...prices].sort((a, b) => a - b);
|
|
4267
|
-
let
|
|
4267
|
+
let median2;
|
|
4268
4268
|
if (this.devSingleProvider) {
|
|
4269
|
-
|
|
4269
|
+
median2 = sorted[0];
|
|
4270
4270
|
} else {
|
|
4271
|
-
|
|
4271
|
+
median2 = sorted[1];
|
|
4272
4272
|
const spread = (sorted[2] - sorted[0]) / sorted[0];
|
|
4273
4273
|
if (spread > PRICE_ORACLE_TOLERANCE) {
|
|
4274
4274
|
const names = this.sources.map((s) => s.name).join(", ");
|
|
@@ -4278,10 +4278,10 @@ ${auth.clientId}`;
|
|
|
4278
4278
|
);
|
|
4279
4279
|
}
|
|
4280
4280
|
}
|
|
4281
|
-
const priceCents = Math.round(
|
|
4281
|
+
const priceCents = Math.round(median2 * 100);
|
|
4282
4282
|
const priceWith8Decimals = BigInt(priceCents) * 1000000n;
|
|
4283
4283
|
const totalElapsed = Date.now() - startTime;
|
|
4284
|
-
console.log(`[Price Oracle] Median price: $${
|
|
4284
|
+
console.log(`[Price Oracle] Median price: $${median2.toLocaleString()} \u2014 total time: ${totalElapsed}ms`);
|
|
4285
4285
|
console.log(`[Price Oracle] Price with 8 decimals: ${priceWith8Decimals}`);
|
|
4286
4286
|
return priceWith8Decimals;
|
|
4287
4287
|
}
|
|
@@ -6233,26 +6233,83 @@ var MAKE_PAYMENT_GAS_CEILING = BigInt(1e6);
|
|
|
6233
6233
|
var EXTEND_POSITION_GAS_CEILING = BigInt(1e6);
|
|
6234
6234
|
var LIQUIDATION_COMMIT_GAS_CEILING = BigInt(1e6);
|
|
6235
6235
|
var LIQUIDATION_REVEAL_GAS_CEILING = BigInt(2e6);
|
|
6236
|
-
|
|
6237
|
-
|
|
6238
|
-
|
|
6239
|
-
|
|
6240
|
-
|
|
6241
|
-
|
|
6242
|
-
|
|
6243
|
-
|
|
6244
|
-
|
|
6245
|
-
|
|
6246
|
-
|
|
6236
|
+
var PRIORITY_FEE_FLOOR_WEI = (0, import_ethers.parseUnits)("0.1", "gwei");
|
|
6237
|
+
var PRIORITY_FEE_CAP_WEI = (0, import_ethers.parseUnits)("3", "gwei");
|
|
6238
|
+
var FEE_HISTORY_BLOCK_COUNT = 20;
|
|
6239
|
+
var FEE_HISTORY_REWARD_PERCENTILE = 75;
|
|
6240
|
+
function isJsonRpcSendable(provider) {
|
|
6241
|
+
return typeof provider.send === "function";
|
|
6242
|
+
}
|
|
6243
|
+
function parseFeeHistory(raw) {
|
|
6244
|
+
if (typeof raw !== "object" || raw === null) {
|
|
6245
|
+
throw new Error(`eth_feeHistory returned a non-object result: ${JSON.stringify(raw)}`);
|
|
6246
|
+
}
|
|
6247
|
+
const { baseFeePerGas, reward } = raw;
|
|
6248
|
+
if (!Array.isArray(baseFeePerGas) || baseFeePerGas.length === 0) {
|
|
6249
|
+
throw new Error(
|
|
6250
|
+
`eth_feeHistory returned no baseFeePerGas \u2014 the RPC does not support EIP-1559 fee history: ${JSON.stringify(raw)}`
|
|
6251
|
+
);
|
|
6252
|
+
}
|
|
6253
|
+
if (!Array.isArray(reward) || reward.length === 0) {
|
|
6254
|
+
throw new Error(
|
|
6255
|
+
`eth_feeHistory returned no reward percentiles \u2014 the RPC ignored the rewardPercentiles argument: ${JSON.stringify(raw)}`
|
|
6256
|
+
);
|
|
6257
|
+
}
|
|
6258
|
+
const nextBaseFee = (0, import_ethers.getBigInt)(baseFeePerGas[baseFeePerGas.length - 1], "baseFeePerGas");
|
|
6259
|
+
const tips = reward.map((perBlock, i) => {
|
|
6260
|
+
if (!Array.isArray(perBlock) || perBlock.length === 0) {
|
|
6261
|
+
throw new Error(`eth_feeHistory reward row ${i} is empty: ${JSON.stringify(raw)}`);
|
|
6262
|
+
}
|
|
6263
|
+
return (0, import_ethers.getBigInt)(perBlock[0], `reward[${i}]`);
|
|
6264
|
+
});
|
|
6265
|
+
return { nextBaseFee, tips };
|
|
6266
|
+
}
|
|
6267
|
+
function median(values) {
|
|
6268
|
+
const sorted = [...values].sort((a, b) => a < b ? -1 : a > b ? 1 : 0);
|
|
6269
|
+
const mid = sorted.length >> 1;
|
|
6270
|
+
const hi = sorted[mid];
|
|
6271
|
+
if (hi === void 0) {
|
|
6272
|
+
throw new Error("median: no values");
|
|
6273
|
+
}
|
|
6274
|
+
if (sorted.length % 2 === 1)
|
|
6275
|
+
return hi;
|
|
6276
|
+
const lo = sorted[mid - 1];
|
|
6277
|
+
if (lo === void 0) {
|
|
6278
|
+
throw new Error("median: no values");
|
|
6279
|
+
}
|
|
6280
|
+
return (lo + hi) / 2n;
|
|
6281
|
+
}
|
|
6282
|
+
function clamp(value, floor, cap) {
|
|
6283
|
+
if (value < floor)
|
|
6284
|
+
return floor;
|
|
6285
|
+
if (value > cap)
|
|
6286
|
+
return cap;
|
|
6287
|
+
return value;
|
|
6288
|
+
}
|
|
6289
|
+
async function resolveEip1559FeeFields(feeProvider) {
|
|
6290
|
+
if (!isJsonRpcSendable(feeProvider)) {
|
|
6291
|
+
throw new Error(
|
|
6292
|
+
"resolveEip1559FeeFields: feeProvider must be a JSON-RPC provider exposing send() (the SDK read provider), not a wallet BrowserProvider \u2014 eth_feeHistory is required"
|
|
6293
|
+
);
|
|
6247
6294
|
}
|
|
6295
|
+
const history = parseFeeHistory(
|
|
6296
|
+
await feeProvider.send("eth_feeHistory", [
|
|
6297
|
+
(0, import_ethers.toQuantity)(FEE_HISTORY_BLOCK_COUNT),
|
|
6298
|
+
"latest",
|
|
6299
|
+
[FEE_HISTORY_REWARD_PERCENTILE]
|
|
6300
|
+
])
|
|
6301
|
+
);
|
|
6302
|
+
const marketTip = median(history.tips);
|
|
6303
|
+
const maxPriorityFeePerGas = clamp(marketTip, PRIORITY_FEE_FLOOR_WEI, PRIORITY_FEE_CAP_WEI);
|
|
6304
|
+
const maxFeePerGas = history.nextBaseFee * 2n + maxPriorityFeePerGas;
|
|
6248
6305
|
return { maxFeePerGas, maxPriorityFeePerGas };
|
|
6249
6306
|
}
|
|
6250
6307
|
async function sendEip1559Transaction(params) {
|
|
6251
|
-
const { signer, to, data, gasLimit } = params;
|
|
6308
|
+
const { signer, feeProvider, to, data, gasLimit } = params;
|
|
6252
6309
|
if (!signer.provider) {
|
|
6253
6310
|
throw new Error("Signer must have a provider attached");
|
|
6254
6311
|
}
|
|
6255
|
-
const fees = await resolveEip1559FeeFields(
|
|
6312
|
+
const fees = await resolveEip1559FeeFields(feeProvider);
|
|
6256
6313
|
return signer.sendTransaction({
|
|
6257
6314
|
to,
|
|
6258
6315
|
data,
|
|
@@ -21209,6 +21266,7 @@ Message: ${causeMessage}${quantumContext}${mintDebtDiagnostics}`
|
|
|
21209
21266
|
}
|
|
21210
21267
|
const tx = await sendEip1559Transaction({
|
|
21211
21268
|
signer,
|
|
21269
|
+
feeProvider: this.getProviderOrThrow(),
|
|
21212
21270
|
to: positionManagerAddress,
|
|
21213
21271
|
data: mintCalldata,
|
|
21214
21272
|
gasLimit: MINT_UCD_GAS_CEILING
|
|
@@ -22430,6 +22488,7 @@ Message: ${causeMessage}${quantumContext}${mintDebtDiagnostics}`
|
|
|
22430
22488
|
}
|
|
22431
22489
|
const tx = await sendEip1559Transaction({
|
|
22432
22490
|
signer: extendSigner,
|
|
22491
|
+
feeProvider: this.getProviderOrThrow(),
|
|
22433
22492
|
to: extendTo,
|
|
22434
22493
|
data: extendCalldata,
|
|
22435
22494
|
gasLimit: EXTEND_POSITION_GAS_CEILING
|
|
@@ -23358,6 +23417,7 @@ Message: ${causeMessage}${quantumContext}${mintDebtDiagnostics}`
|
|
|
23358
23417
|
}
|
|
23359
23418
|
const tx = await sendEip1559Transaction({
|
|
23360
23419
|
signer: paymentSigner,
|
|
23420
|
+
feeProvider: this.getProviderOrThrow(),
|
|
23361
23421
|
to: paymentContractAddress,
|
|
23362
23422
|
data: paymentCalldata,
|
|
23363
23423
|
gasLimit: MAKE_PAYMENT_GAS_CEILING
|
|
@@ -24123,6 +24183,7 @@ Message: ${causeMessage}${quantumContext}${mintDebtDiagnostics}`
|
|
|
24123
24183
|
});
|
|
24124
24184
|
tx = await sendEip1559Transaction({
|
|
24125
24185
|
signer: withdrawSigner,
|
|
24186
|
+
feeProvider: this.getProviderOrThrow(),
|
|
24126
24187
|
to: positionManagerAddress,
|
|
24127
24188
|
data: withdrawCalldata,
|
|
24128
24189
|
gasLimit: WITHDRAW_BTC_GAS_CEILING
|
package/dist/index.mjs
CHANGED
|
@@ -4270,11 +4270,11 @@ ${auth.clientId}`;
|
|
|
4270
4270
|
);
|
|
4271
4271
|
const prices = await Promise.race([fetchAll, timeoutPromise]);
|
|
4272
4272
|
const sorted = [...prices].sort((a, b) => a - b);
|
|
4273
|
-
let
|
|
4273
|
+
let median2;
|
|
4274
4274
|
if (this.devSingleProvider) {
|
|
4275
|
-
|
|
4275
|
+
median2 = sorted[0];
|
|
4276
4276
|
} else {
|
|
4277
|
-
|
|
4277
|
+
median2 = sorted[1];
|
|
4278
4278
|
const spread = (sorted[2] - sorted[0]) / sorted[0];
|
|
4279
4279
|
if (spread > PRICE_ORACLE_TOLERANCE) {
|
|
4280
4280
|
const names = this.sources.map((s) => s.name).join(", ");
|
|
@@ -4284,10 +4284,10 @@ ${auth.clientId}`;
|
|
|
4284
4284
|
);
|
|
4285
4285
|
}
|
|
4286
4286
|
}
|
|
4287
|
-
const priceCents = Math.round(
|
|
4287
|
+
const priceCents = Math.round(median2 * 100);
|
|
4288
4288
|
const priceWith8Decimals = BigInt(priceCents) * 1000000n;
|
|
4289
4289
|
const totalElapsed = Date.now() - startTime;
|
|
4290
|
-
console.log(`[Price Oracle] Median price: $${
|
|
4290
|
+
console.log(`[Price Oracle] Median price: $${median2.toLocaleString()} \u2014 total time: ${totalElapsed}ms`);
|
|
4291
4291
|
console.log(`[Price Oracle] Price with 8 decimals: ${priceWith8Decimals}`);
|
|
4292
4292
|
return priceWith8Decimals;
|
|
4293
4293
|
}
|
|
@@ -6137,33 +6137,94 @@ var SDKError = class _SDKError extends Error {
|
|
|
6137
6137
|
};
|
|
6138
6138
|
|
|
6139
6139
|
// src/utils/chunks/eip1559-broadcast.utils.ts
|
|
6140
|
-
import {
|
|
6140
|
+
import {
|
|
6141
|
+
getBigInt,
|
|
6142
|
+
parseUnits,
|
|
6143
|
+
toQuantity
|
|
6144
|
+
} from "ethers";
|
|
6141
6145
|
var MINT_UCD_GAS_CEILING = BigInt(13e5);
|
|
6142
6146
|
var WITHDRAW_BTC_GAS_CEILING = BigInt(3e6);
|
|
6143
6147
|
var MAKE_PAYMENT_GAS_CEILING = BigInt(1e6);
|
|
6144
6148
|
var EXTEND_POSITION_GAS_CEILING = BigInt(1e6);
|
|
6145
6149
|
var LIQUIDATION_COMMIT_GAS_CEILING = BigInt(1e6);
|
|
6146
6150
|
var LIQUIDATION_REVEAL_GAS_CEILING = BigInt(2e6);
|
|
6147
|
-
|
|
6148
|
-
|
|
6149
|
-
|
|
6150
|
-
|
|
6151
|
-
|
|
6152
|
-
|
|
6153
|
-
|
|
6154
|
-
|
|
6155
|
-
|
|
6156
|
-
|
|
6157
|
-
|
|
6151
|
+
var PRIORITY_FEE_FLOOR_WEI = parseUnits("0.1", "gwei");
|
|
6152
|
+
var PRIORITY_FEE_CAP_WEI = parseUnits("3", "gwei");
|
|
6153
|
+
var FEE_HISTORY_BLOCK_COUNT = 20;
|
|
6154
|
+
var FEE_HISTORY_REWARD_PERCENTILE = 75;
|
|
6155
|
+
function isJsonRpcSendable(provider) {
|
|
6156
|
+
return typeof provider.send === "function";
|
|
6157
|
+
}
|
|
6158
|
+
function parseFeeHistory(raw) {
|
|
6159
|
+
if (typeof raw !== "object" || raw === null) {
|
|
6160
|
+
throw new Error(`eth_feeHistory returned a non-object result: ${JSON.stringify(raw)}`);
|
|
6161
|
+
}
|
|
6162
|
+
const { baseFeePerGas, reward } = raw;
|
|
6163
|
+
if (!Array.isArray(baseFeePerGas) || baseFeePerGas.length === 0) {
|
|
6164
|
+
throw new Error(
|
|
6165
|
+
`eth_feeHistory returned no baseFeePerGas \u2014 the RPC does not support EIP-1559 fee history: ${JSON.stringify(raw)}`
|
|
6166
|
+
);
|
|
6167
|
+
}
|
|
6168
|
+
if (!Array.isArray(reward) || reward.length === 0) {
|
|
6169
|
+
throw new Error(
|
|
6170
|
+
`eth_feeHistory returned no reward percentiles \u2014 the RPC ignored the rewardPercentiles argument: ${JSON.stringify(raw)}`
|
|
6171
|
+
);
|
|
6158
6172
|
}
|
|
6173
|
+
const nextBaseFee = getBigInt(baseFeePerGas[baseFeePerGas.length - 1], "baseFeePerGas");
|
|
6174
|
+
const tips = reward.map((perBlock, i) => {
|
|
6175
|
+
if (!Array.isArray(perBlock) || perBlock.length === 0) {
|
|
6176
|
+
throw new Error(`eth_feeHistory reward row ${i} is empty: ${JSON.stringify(raw)}`);
|
|
6177
|
+
}
|
|
6178
|
+
return getBigInt(perBlock[0], `reward[${i}]`);
|
|
6179
|
+
});
|
|
6180
|
+
return { nextBaseFee, tips };
|
|
6181
|
+
}
|
|
6182
|
+
function median(values) {
|
|
6183
|
+
const sorted = [...values].sort((a, b) => a < b ? -1 : a > b ? 1 : 0);
|
|
6184
|
+
const mid = sorted.length >> 1;
|
|
6185
|
+
const hi = sorted[mid];
|
|
6186
|
+
if (hi === void 0) {
|
|
6187
|
+
throw new Error("median: no values");
|
|
6188
|
+
}
|
|
6189
|
+
if (sorted.length % 2 === 1)
|
|
6190
|
+
return hi;
|
|
6191
|
+
const lo = sorted[mid - 1];
|
|
6192
|
+
if (lo === void 0) {
|
|
6193
|
+
throw new Error("median: no values");
|
|
6194
|
+
}
|
|
6195
|
+
return (lo + hi) / 2n;
|
|
6196
|
+
}
|
|
6197
|
+
function clamp(value, floor, cap) {
|
|
6198
|
+
if (value < floor)
|
|
6199
|
+
return floor;
|
|
6200
|
+
if (value > cap)
|
|
6201
|
+
return cap;
|
|
6202
|
+
return value;
|
|
6203
|
+
}
|
|
6204
|
+
async function resolveEip1559FeeFields(feeProvider) {
|
|
6205
|
+
if (!isJsonRpcSendable(feeProvider)) {
|
|
6206
|
+
throw new Error(
|
|
6207
|
+
"resolveEip1559FeeFields: feeProvider must be a JSON-RPC provider exposing send() (the SDK read provider), not a wallet BrowserProvider \u2014 eth_feeHistory is required"
|
|
6208
|
+
);
|
|
6209
|
+
}
|
|
6210
|
+
const history = parseFeeHistory(
|
|
6211
|
+
await feeProvider.send("eth_feeHistory", [
|
|
6212
|
+
toQuantity(FEE_HISTORY_BLOCK_COUNT),
|
|
6213
|
+
"latest",
|
|
6214
|
+
[FEE_HISTORY_REWARD_PERCENTILE]
|
|
6215
|
+
])
|
|
6216
|
+
);
|
|
6217
|
+
const marketTip = median(history.tips);
|
|
6218
|
+
const maxPriorityFeePerGas = clamp(marketTip, PRIORITY_FEE_FLOOR_WEI, PRIORITY_FEE_CAP_WEI);
|
|
6219
|
+
const maxFeePerGas = history.nextBaseFee * 2n + maxPriorityFeePerGas;
|
|
6159
6220
|
return { maxFeePerGas, maxPriorityFeePerGas };
|
|
6160
6221
|
}
|
|
6161
6222
|
async function sendEip1559Transaction(params) {
|
|
6162
|
-
const { signer, to, data, gasLimit } = params;
|
|
6223
|
+
const { signer, feeProvider, to, data, gasLimit } = params;
|
|
6163
6224
|
if (!signer.provider) {
|
|
6164
6225
|
throw new Error("Signer must have a provider attached");
|
|
6165
6226
|
}
|
|
6166
|
-
const fees = await resolveEip1559FeeFields(
|
|
6227
|
+
const fees = await resolveEip1559FeeFields(feeProvider);
|
|
6167
6228
|
return signer.sendTransaction({
|
|
6168
6229
|
to,
|
|
6169
6230
|
data,
|
|
@@ -21134,6 +21195,7 @@ Message: ${causeMessage}${quantumContext}${mintDebtDiagnostics}`
|
|
|
21134
21195
|
}
|
|
21135
21196
|
const tx = await sendEip1559Transaction({
|
|
21136
21197
|
signer,
|
|
21198
|
+
feeProvider: this.getProviderOrThrow(),
|
|
21137
21199
|
to: positionManagerAddress,
|
|
21138
21200
|
data: mintCalldata,
|
|
21139
21201
|
gasLimit: MINT_UCD_GAS_CEILING
|
|
@@ -22355,6 +22417,7 @@ Message: ${causeMessage}${quantumContext}${mintDebtDiagnostics}`
|
|
|
22355
22417
|
}
|
|
22356
22418
|
const tx = await sendEip1559Transaction({
|
|
22357
22419
|
signer: extendSigner,
|
|
22420
|
+
feeProvider: this.getProviderOrThrow(),
|
|
22358
22421
|
to: extendTo,
|
|
22359
22422
|
data: extendCalldata,
|
|
22360
22423
|
gasLimit: EXTEND_POSITION_GAS_CEILING
|
|
@@ -23283,6 +23346,7 @@ Message: ${causeMessage}${quantumContext}${mintDebtDiagnostics}`
|
|
|
23283
23346
|
}
|
|
23284
23347
|
const tx = await sendEip1559Transaction({
|
|
23285
23348
|
signer: paymentSigner,
|
|
23349
|
+
feeProvider: this.getProviderOrThrow(),
|
|
23286
23350
|
to: paymentContractAddress,
|
|
23287
23351
|
data: paymentCalldata,
|
|
23288
23352
|
gasLimit: MAKE_PAYMENT_GAS_CEILING
|
|
@@ -24048,6 +24112,7 @@ Message: ${causeMessage}${quantumContext}${mintDebtDiagnostics}`
|
|
|
24048
24112
|
});
|
|
24049
24113
|
tx = await sendEip1559Transaction({
|
|
24050
24114
|
signer: withdrawSigner,
|
|
24115
|
+
feeProvider: this.getProviderOrThrow(),
|
|
24051
24116
|
to: positionManagerAddress,
|
|
24052
24117
|
data: withdrawCalldata,
|
|
24053
24118
|
gasLimit: WITHDRAW_BTC_GAS_CEILING
|
|
@@ -24,9 +24,14 @@ export declare const MINT_UCD_GAS_CEILING: bigint;
|
|
|
24
24
|
* gasLimit — no estimateGas runs on this path). The on-chain flow now spans PositionManager →
|
|
25
25
|
* CollateralManager → LoanOperationsManager → BTCSpendAuthorizer plus the audit
|
|
26
26
|
* #3 Chainlink feed-staleness gate and the BitcoinWithdrawalAddressRegistry
|
|
27
|
-
* allowlist STATICCALL; observed end-to-end cost
|
|
28
|
-
* hardcoded 1,000,000 limit caused a nested out-of-gas.
|
|
29
|
-
*
|
|
27
|
+
* allowlist STATICCALL; observed end-to-end cost was ~1.0–1.3M gas when this
|
|
28
|
+
* was sized, so the prior hardcoded 1,000,000 limit caused a nested out-of-gas.
|
|
29
|
+
* A mainnet withdrawBTC measured 750,919 gas on 2026-09-04 (2 vault inputs,
|
|
30
|
+
* 1 prior reservation; tx 0xa244a184…) — recorded as a data point, NOT a new
|
|
31
|
+
* ceiling basis: cost grows with the number of open reservations
|
|
32
|
+
* (`_computeAuthorizedSpendsHash` is O(N)), so the ceiling stays sized to the
|
|
33
|
+
* observed MAX. 3M gives ~2x headroom over it while staying well under the
|
|
34
|
+
* block gas limit.
|
|
30
35
|
*/
|
|
31
36
|
export declare const WITHDRAW_BTC_GAS_CEILING: bigint;
|
|
32
37
|
/**
|
|
@@ -86,12 +91,60 @@ export declare const LIQUIDATION_COMMIT_GAS_CEILING: bigint;
|
|
|
86
91
|
* provisional until re-measured against a real liquidation.
|
|
87
92
|
*/
|
|
88
93
|
export declare const LIQUIDATION_REVEAL_GAS_CEILING: bigint;
|
|
89
|
-
|
|
94
|
+
/**
|
|
95
|
+
* Priority-fee (tip) policy for every timing-sensitive broadcast in this file.
|
|
96
|
+
*
|
|
97
|
+
* History that sizes these numbers (docs/withdraw-btc-gas-cost-recommendations-2026-09-05.md):
|
|
98
|
+
* - 2026-07-02: a 0 gwei tip (the read RPC reported a real 0n
|
|
99
|
+
* eth_maxPriorityFeePerGas) sat unmined 119–143 s → QuantumOutsideWindow.
|
|
100
|
+
* - 2026-08-07: a 0.0007 gwei tip was skipped by one NEAR-EMPTY block, mined
|
|
101
|
+
* 24 s later → DeadZoneViolation (see quantum-timing.ts).
|
|
102
|
+
* - 2026-09-04: a mainnet withdrawBTC went out with ethers' hardcoded 1 gwei
|
|
103
|
+
* fallback tip (the wallet provider did not answer eth_maxPriorityFeePerGas)
|
|
104
|
+
* while the market p50 tip was ~0.03 gwei — 93% of a $1.99 tx was tip.
|
|
105
|
+
*
|
|
106
|
+
* So the tip is read from the market (eth_feeHistory on the app's READ RPC,
|
|
107
|
+
* never the wallet provider) at a percentile that buys next-block inclusion,
|
|
108
|
+
* then clamped: the floor keeps builders from skipping us (a quantum miss
|
|
109
|
+
* wastes the Lit signatures, the Chipotle spend and the reverted tx's base
|
|
110
|
+
* fee — far more than the tip), the cap stops a spiking feeHistory from
|
|
111
|
+
* overpaying. At ~751k gas the floor costs ≈ $0.18 (ETH $2,458).
|
|
112
|
+
*/
|
|
113
|
+
export declare const PRIORITY_FEE_FLOOR_WEI: bigint;
|
|
114
|
+
export declare const PRIORITY_FEE_CAP_WEI: bigint;
|
|
115
|
+
/** Blocks of eth_feeHistory sampled; the median across them absorbs a single spike block. */
|
|
116
|
+
export declare const FEE_HISTORY_BLOCK_COUNT = 20;
|
|
117
|
+
/**
|
|
118
|
+
* Reward percentile per block. p75 (not p50) because these sends are
|
|
119
|
+
* quantum-bounded: paying above the median tip buys inclusion in the next
|
|
120
|
+
* slot or two, which is what the 60 s window actually needs.
|
|
121
|
+
*/
|
|
122
|
+
export declare const FEE_HISTORY_REWARD_PERCENTILE = 75;
|
|
123
|
+
/** The subset of ethers' JsonRpcApiProvider these helpers need — raw JSON-RPC access. */
|
|
124
|
+
export interface JsonRpcSendable {
|
|
125
|
+
send(method: string, params: unknown[]): Promise<unknown>;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Resolve EIP-1559 fee fields from the app's READ RPC.
|
|
129
|
+
*
|
|
130
|
+
* `feeProvider` must be a JSON-RPC provider (ethers `JsonRpcProvider` or any
|
|
131
|
+
* object exposing `send`), NOT the wallet's `BrowserProvider`: wallet
|
|
132
|
+
* providers routinely fail `eth_maxPriorityFeePerGas`, and ethers'
|
|
133
|
+
* `getFeeData()` then silently substitutes a 1 gwei tip — the 2026-09-04
|
|
134
|
+
* overpayment. This helper never calls `getFeeData()`.
|
|
135
|
+
*
|
|
136
|
+
* One `eth_feeHistory` round-trip replaces the three RPC calls `getFeeData()`
|
|
137
|
+
* made (block, gasPrice, priorityFee), so it is also faster on the
|
|
138
|
+
* quantum-gated path that runs right before the send.
|
|
139
|
+
*/
|
|
140
|
+
export declare function resolveEip1559FeeFields(feeProvider: Provider): Promise<{
|
|
90
141
|
maxFeePerGas: bigint;
|
|
91
142
|
maxPriorityFeePerGas: bigint;
|
|
92
143
|
}>;
|
|
93
144
|
export declare function sendEip1559Transaction(params: {
|
|
94
145
|
signer: Signer;
|
|
146
|
+
/** The SDK READ provider (JSON-RPC). Fee fields come from here, never from `signer.provider`. */
|
|
147
|
+
feeProvider: Provider;
|
|
95
148
|
to: string;
|
|
96
149
|
data: string;
|
|
97
150
|
gasLimit: bigint;
|
package/package.json
CHANGED