@keplr-wallet/background 0.13.35 → 0.13.36
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/build/keyring/service.js +31 -42
- package/build/keyring/service.js.map +1 -1
- package/build/keyring/service.spec.d.ts +1 -0
- package/build/keyring/service.spec.js +106 -0
- package/build/keyring/service.spec.js.map +1 -0
- package/build/tx-executor/index.d.ts +1 -0
- package/build/tx-executor/index.js +1 -0
- package/build/tx-executor/index.js.map +1 -1
- package/build/tx-executor/service.d.ts +8 -5
- package/build/tx-executor/service.js +56 -11
- package/build/tx-executor/service.js.map +1 -1
- package/build/tx-executor/types.d.ts +20 -1
- package/build/tx-executor/utils/diagnostics.d.ts +14 -0
- package/build/tx-executor/utils/diagnostics.js +215 -0
- package/build/tx-executor/utils/diagnostics.js.map +1 -0
- package/build/tx-executor/utils/diagnostics.spec.d.ts +1 -0
- package/build/tx-executor/utils/diagnostics.spec.js +48 -0
- package/build/tx-executor/utils/diagnostics.spec.js.map +1 -0
- package/build/tx-executor/utils/evm.js +7 -3
- package/build/tx-executor/utils/evm.js.map +1 -1
- package/build/tx-executor/utils/evm.spec.d.ts +1 -0
- package/build/tx-executor/utils/evm.spec.js +59 -0
- package/build/tx-executor/utils/evm.spec.js.map +1 -0
- package/package.json +13 -13
- package/src/keyring/service.spec.ts +141 -0
- package/src/keyring/service.ts +47 -59
- package/src/tx-executor/index.ts +1 -0
- package/src/tx-executor/service.ts +72 -17
- package/src/tx-executor/types.ts +42 -1
- package/src/tx-executor/utils/diagnostics.spec.ts +89 -0
- package/src/tx-executor/utils/diagnostics.ts +298 -0
- package/src/tx-executor/utils/evm.spec.ts +62 -0
- package/src/tx-executor/utils/evm.ts +18 -1
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { EVMInfo } from "@keplr-wallet/types";
|
|
2
|
+
import { getTxExecutionDiagnostics } from "./diagnostics";
|
|
3
|
+
import { fillUnsignedEVMTx } from "./evm";
|
|
4
|
+
import { fetchWithRetry } from "./fetch";
|
|
5
|
+
|
|
6
|
+
jest.mock("./fetch", () => ({
|
|
7
|
+
fetchWithRetry: jest.fn(),
|
|
8
|
+
}));
|
|
9
|
+
|
|
10
|
+
const mockFetchWithRetry = fetchWithRetry as jest.MockedFunction<
|
|
11
|
+
typeof fetchWithRetry
|
|
12
|
+
>;
|
|
13
|
+
|
|
14
|
+
describe("fillUnsignedEVMTx", () => {
|
|
15
|
+
beforeEach(() => {
|
|
16
|
+
mockFetchWithRetry.mockReset();
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it("keeps eth_estimateGas optional and adds diagnostics only at final gas failure", async () => {
|
|
20
|
+
mockFetchWithRetry.mockResolvedValue({
|
|
21
|
+
data: [
|
|
22
|
+
{ id: 1, result: "0x1" },
|
|
23
|
+
{ id: 2, result: { baseFeePerGas: "0x1" } },
|
|
24
|
+
{ id: 3, result: {} },
|
|
25
|
+
{
|
|
26
|
+
id: 4,
|
|
27
|
+
error: {
|
|
28
|
+
code: -32000,
|
|
29
|
+
message:
|
|
30
|
+
"execution reverted: ERC20: transfer amount exceeds allowance",
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
{ id: 5, result: "0x1" },
|
|
34
|
+
{ id: 6, result: "0x1" },
|
|
35
|
+
],
|
|
36
|
+
} as any);
|
|
37
|
+
|
|
38
|
+
try {
|
|
39
|
+
await fillUnsignedEVMTx(
|
|
40
|
+
"extension",
|
|
41
|
+
{ rpc: "https://example.invalid" } as EVMInfo,
|
|
42
|
+
"0xsender",
|
|
43
|
+
{
|
|
44
|
+
to: "0xrouter",
|
|
45
|
+
value: "0x0",
|
|
46
|
+
data: "0x",
|
|
47
|
+
}
|
|
48
|
+
);
|
|
49
|
+
throw new Error("Expected fillUnsignedEVMTx to fail");
|
|
50
|
+
} catch (e) {
|
|
51
|
+
expect((e as Error).message).toBe(
|
|
52
|
+
"Failed to estimate gas to fill unsigned transaction"
|
|
53
|
+
);
|
|
54
|
+
expect(getTxExecutionDiagnostics(e)).toEqual({
|
|
55
|
+
gas_estimate_context: "background_fill_unsigned_tx",
|
|
56
|
+
gas_estimate_error_category: "allowance_insufficient",
|
|
57
|
+
failed_tx_has_required_erc20_approval: false,
|
|
58
|
+
failed_tx_has_native_value: false,
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
});
|
|
@@ -4,6 +4,10 @@ import { Dec } from "@keplr-wallet/unit";
|
|
|
4
4
|
import { BackgroundTxFeeType, EVMBackgroundTxFeeType } from "../types";
|
|
5
5
|
import { JsonRpcResponse } from "@keplr-wallet/types";
|
|
6
6
|
import { fetchWithRetry } from "./fetch";
|
|
7
|
+
import {
|
|
8
|
+
createGasEstimateDiagnostics,
|
|
9
|
+
TxExecutionDiagnosticsError,
|
|
10
|
+
} from "./diagnostics";
|
|
7
11
|
|
|
8
12
|
const ETH_FEE_HISTORY_REWARD_PERCENTILES = [20, 40, 60];
|
|
9
13
|
const ETH_FEE_SETTINGS_BY_FEE_TYPE: Record<
|
|
@@ -189,6 +193,9 @@ export async function fillUnsignedEVMTx(
|
|
|
189
193
|
? Math.max(Number(tx.nonce), parseInt(nonceHex, 16))
|
|
190
194
|
: parseInt(nonceHex, 16);
|
|
191
195
|
|
|
196
|
+
const estimateGasResponse = hasProvidedGasLimit
|
|
197
|
+
? undefined
|
|
198
|
+
: rpcResponses.find((r) => r.id === ESTIMATE_GAS_ID);
|
|
192
199
|
const gasLimitHex = hasProvidedGasLimit
|
|
193
200
|
? undefined
|
|
194
201
|
: getResult<string>(ESTIMATE_GAS_ID, true);
|
|
@@ -203,7 +210,17 @@ export async function fillUnsignedEVMTx(
|
|
|
203
210
|
GAS_ADJUSTMENT_DEN;
|
|
204
211
|
finalGasLimit = `0x${adjustedGas.toString(16)}`;
|
|
205
212
|
} else {
|
|
206
|
-
throw new
|
|
213
|
+
throw new TxExecutionDiagnosticsError(
|
|
214
|
+
"Failed to estimate gas to fill unsigned transaction",
|
|
215
|
+
createGasEstimateDiagnostics(
|
|
216
|
+
new Error(
|
|
217
|
+
estimateGasResponse?.error?.message ??
|
|
218
|
+
"Missing eth_estimateGas result"
|
|
219
|
+
),
|
|
220
|
+
"background_fill_unsigned_tx",
|
|
221
|
+
tx as UnsignedTransaction & { requiredErc20Approvals?: unknown[] }
|
|
222
|
+
)
|
|
223
|
+
);
|
|
207
224
|
}
|
|
208
225
|
|
|
209
226
|
// Legacy chain detection: baseFeePerGas missing or zero
|