@0xkey-io/gas-station 0.1.0
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/LICENSE +201 -0
- package/README.md +655 -0
- package/dist/abi/gas-station.d.ts +500 -0
- package/dist/abi/gas-station.d.ts.map +1 -0
- package/dist/abi/gas-station.js +252 -0
- package/dist/abi/gas-station.js.map +1 -0
- package/dist/abi/gas-station.mjs +250 -0
- package/dist/abi/gas-station.mjs.map +1 -0
- package/dist/abi/reimbursable-gas-station.d.ts +756 -0
- package/dist/abi/reimbursable-gas-station.d.ts.map +1 -0
- package/dist/abi/reimbursable-gas-station.js +625 -0
- package/dist/abi/reimbursable-gas-station.js.map +1 -0
- package/dist/abi/reimbursable-gas-station.mjs +623 -0
- package/dist/abi/reimbursable-gas-station.mjs.map +1 -0
- package/dist/config.d.ts +57 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +59 -0
- package/dist/config.js.map +1 -0
- package/dist/config.mjs +52 -0
- package/dist/config.mjs.map +1 -0
- package/dist/gasStationClient.d.ts +110 -0
- package/dist/gasStationClient.d.ts.map +1 -0
- package/dist/gasStationClient.js +415 -0
- package/dist/gasStationClient.js.map +1 -0
- package/dist/gasStationClient.mjs +413 -0
- package/dist/gasStationClient.mjs.map +1 -0
- package/dist/gasStationUtils.d.ts +7250 -0
- package/dist/gasStationUtils.d.ts.map +1 -0
- package/dist/gasStationUtils.js +147 -0
- package/dist/gasStationUtils.js.map +1 -0
- package/dist/gasStationUtils.mjs +137 -0
- package/dist/gasStationUtils.mjs.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +36 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +8 -0
- package/dist/index.mjs.map +1 -0
- package/dist/intentBuilder.d.ts +75 -0
- package/dist/intentBuilder.d.ts.map +1 -0
- package/dist/intentBuilder.js +259 -0
- package/dist/intentBuilder.js.map +1 -0
- package/dist/intentBuilder.mjs +257 -0
- package/dist/intentBuilder.mjs.map +1 -0
- package/dist/policyUtils.d.ts +271 -0
- package/dist/policyUtils.d.ts.map +1 -0
- package/dist/policyUtils.js +386 -0
- package/dist/policyUtils.js.map +1 -0
- package/dist/policyUtils.mjs +380 -0
- package/dist/policyUtils.mjs.map +1 -0
- package/package.json +61 -0
|
@@ -0,0 +1,413 @@
|
|
|
1
|
+
import { encodeFunctionData } from 'viem';
|
|
2
|
+
import { gasStationAbi } from './abi/gas-station.mjs';
|
|
3
|
+
import { reimbursableGasStationAbi } from './abi/reimbursable-gas-station.mjs';
|
|
4
|
+
import { DEFAULT_DELEGATE_CONTRACT, DEFAULT_EXECUTION_CONTRACT, DEFAULT_REIMBURSABLE_USDC_CONTRACT } from './config.mjs';
|
|
5
|
+
import { IntentBuilder } from './intentBuilder.mjs';
|
|
6
|
+
import { createPublicClientForChain, packExecutionData } from './gasStationUtils.mjs';
|
|
7
|
+
|
|
8
|
+
class GasStationClient {
|
|
9
|
+
constructor(config) {
|
|
10
|
+
this.walletClient = config.walletClient;
|
|
11
|
+
this.publicClient = createPublicClientForChain(config.walletClient.chain, config.walletClient.transport.url);
|
|
12
|
+
this.delegateContract =
|
|
13
|
+
config.delegateContract ?? DEFAULT_DELEGATE_CONTRACT;
|
|
14
|
+
this.executionContract =
|
|
15
|
+
config.executionContract ?? DEFAULT_EXECUTION_CONTRACT;
|
|
16
|
+
this.reimbursableContract =
|
|
17
|
+
config.reimbursableContract ?? DEFAULT_REIMBURSABLE_USDC_CONTRACT;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Sign an EIP-7702 authorization to delegate control to the gas station contract
|
|
21
|
+
* Call this with an end-user client to get a signed authorization
|
|
22
|
+
* The authorization can then be submitted by the paymaster using submitAuthorization()
|
|
23
|
+
*/
|
|
24
|
+
async signAuthorization(chainId) {
|
|
25
|
+
const authorization = await this.walletClient.signAuthorization({
|
|
26
|
+
contractAddress: this.delegateContract,
|
|
27
|
+
account: this.walletClient.account,
|
|
28
|
+
chainId: chainId ?? 0, // 0 means valid on any EIP-7702 compatible chain
|
|
29
|
+
});
|
|
30
|
+
return authorization;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Submit signed EIP-7702 authorization transaction(s)
|
|
34
|
+
* Supports authorizing multiple EOAs in a single transaction
|
|
35
|
+
* Call this with a paymaster client to broadcast the authorization transaction
|
|
36
|
+
* The paymaster pays for the gas
|
|
37
|
+
*/
|
|
38
|
+
async submitAuthorizations(authorizations) {
|
|
39
|
+
if (authorizations.length === 0) {
|
|
40
|
+
throw new Error("Authorization list cannot be empty");
|
|
41
|
+
}
|
|
42
|
+
const authTxHash = await this.walletClient.sendTransaction({
|
|
43
|
+
from: "0x0000000000000000000000000000000000000000",
|
|
44
|
+
authorizationList: authorizations,
|
|
45
|
+
to: "0x0000000000000000000000000000000000000000",
|
|
46
|
+
type: "eip7702",
|
|
47
|
+
account: this.walletClient.account,
|
|
48
|
+
});
|
|
49
|
+
const receipt = await this.publicClient.waitForTransactionReceipt({
|
|
50
|
+
hash: authTxHash,
|
|
51
|
+
});
|
|
52
|
+
if (receipt.status !== "success") {
|
|
53
|
+
// Try to get the revert reason if available
|
|
54
|
+
const revertReason = await this.getRevertReason(authTxHash);
|
|
55
|
+
throw new Error(`Authorization failed: ${revertReason || "Transaction reverted"}. ` +
|
|
56
|
+
`Gas used: ${receipt.gasUsed}/${receipt.cumulativeGasUsed}. ` +
|
|
57
|
+
`Transaction hash: ${authTxHash}`);
|
|
58
|
+
}
|
|
59
|
+
return { txHash: authTxHash, blockNumber: receipt.blockNumber };
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Check if an EOA is delegated to the gas station contract
|
|
63
|
+
* If no address is provided, uses the signer's address
|
|
64
|
+
*/
|
|
65
|
+
async isAuthorized(eoaAddress) {
|
|
66
|
+
const address = eoaAddress ?? this.walletClient.account.address;
|
|
67
|
+
const isAuthorized = await this.publicClient.readContract({
|
|
68
|
+
address: this.executionContract,
|
|
69
|
+
abi: gasStationAbi,
|
|
70
|
+
functionName: "isDelegated",
|
|
71
|
+
args: [address],
|
|
72
|
+
});
|
|
73
|
+
return isAuthorized;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Get the current nonce for an EOA address from the gas station contract
|
|
77
|
+
* If no address is provided, uses the signer's address
|
|
78
|
+
*/
|
|
79
|
+
async getNonce(eoaAddress) {
|
|
80
|
+
const address = eoaAddress ?? this.walletClient.account.address;
|
|
81
|
+
const nonce = await this.publicClient.readContract({
|
|
82
|
+
address: this.executionContract,
|
|
83
|
+
abi: gasStationAbi,
|
|
84
|
+
functionName: "getNonce",
|
|
85
|
+
args: [address],
|
|
86
|
+
});
|
|
87
|
+
return nonce;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Attempts to get the revert reason from a failed transaction.
|
|
91
|
+
* Replays the transaction via eth_call to extract detailed error information.
|
|
92
|
+
*
|
|
93
|
+
* This helps surface on-chain failure reasons such as:
|
|
94
|
+
* - Out of gas errors
|
|
95
|
+
* - Revert with reason strings
|
|
96
|
+
* - Custom error selectors
|
|
97
|
+
* - Insufficient balance errors
|
|
98
|
+
*/
|
|
99
|
+
async getRevertReason(txHash) {
|
|
100
|
+
try {
|
|
101
|
+
const tx = await this.publicClient.getTransaction({ hash: txHash });
|
|
102
|
+
// Replay the transaction via eth_call to trigger the revert and get the reason
|
|
103
|
+
await this.publicClient.call({
|
|
104
|
+
to: tx.to,
|
|
105
|
+
data: tx.input,
|
|
106
|
+
gas: tx.gas,
|
|
107
|
+
value: tx.value,
|
|
108
|
+
});
|
|
109
|
+
// If call succeeds, we don't have a revert reason (shouldn't happen for failed tx)
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
catch (error) {
|
|
113
|
+
// Extract revert reason from error message
|
|
114
|
+
if (error?.details) {
|
|
115
|
+
return error.details;
|
|
116
|
+
}
|
|
117
|
+
if (error?.message) {
|
|
118
|
+
// Check for out of gas errors
|
|
119
|
+
const outOfGasMatch = error.message.match(/out of gas/i);
|
|
120
|
+
if (outOfGasMatch) {
|
|
121
|
+
return "Out of gas";
|
|
122
|
+
}
|
|
123
|
+
// Check for standard revert with reason string
|
|
124
|
+
const revertMatch = error.message.match(/reverted with reason string '([^']+)'/);
|
|
125
|
+
if (revertMatch) {
|
|
126
|
+
return revertMatch[1];
|
|
127
|
+
}
|
|
128
|
+
// Check for custom errors (Solidity 0.8.4+)
|
|
129
|
+
const customErrorMatch = error.message.match(/reverted with the following \(custom\) error:\s*([^\n]+)/);
|
|
130
|
+
if (customErrorMatch) {
|
|
131
|
+
return customErrorMatch[1];
|
|
132
|
+
}
|
|
133
|
+
// Return the full error message if no specific pattern matches
|
|
134
|
+
return error.message;
|
|
135
|
+
}
|
|
136
|
+
return null;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Create an intent builder for composing complex transactions
|
|
141
|
+
* Call this with an end-user client to create intents for signing
|
|
142
|
+
*/
|
|
143
|
+
createIntent() {
|
|
144
|
+
if (!this.walletClient.account?.address) {
|
|
145
|
+
throw new Error(`Wallet client account is not properly configured. Account: ${JSON.stringify(this.walletClient.account)}`);
|
|
146
|
+
}
|
|
147
|
+
return IntentBuilder.create({
|
|
148
|
+
eoaWalletClient: this.walletClient,
|
|
149
|
+
chainId: this.walletClient.chain.id,
|
|
150
|
+
eoaAddress: this.walletClient.account.address,
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Sign an execution transaction for a signed intent (paymaster signs, doesn't send)
|
|
155
|
+
* This is useful for testing policies - the paymaster attempts to sign the execution
|
|
156
|
+
* but doesn't actually broadcast it to the network.
|
|
157
|
+
* Call this with a paymaster client to test if the paymaster can sign the execution.
|
|
158
|
+
*/
|
|
159
|
+
async signExecution(intent) {
|
|
160
|
+
// Pack the execution data (signature, nonce, deadline, args)
|
|
161
|
+
const packedData = packExecutionData({
|
|
162
|
+
signature: intent.signature,
|
|
163
|
+
nonce: intent.nonce,
|
|
164
|
+
deadline: intent.deadline,
|
|
165
|
+
args: intent.callData,
|
|
166
|
+
});
|
|
167
|
+
// Encode the function call data
|
|
168
|
+
const callData = encodeFunctionData({
|
|
169
|
+
abi: gasStationAbi,
|
|
170
|
+
functionName: "execute",
|
|
171
|
+
args: [
|
|
172
|
+
intent.eoaAddress,
|
|
173
|
+
intent.outputContract,
|
|
174
|
+
intent.ethAmount,
|
|
175
|
+
packedData,
|
|
176
|
+
],
|
|
177
|
+
});
|
|
178
|
+
// Sign the transaction without sending it
|
|
179
|
+
const signedTx = await this.walletClient.signTransaction({
|
|
180
|
+
to: this.executionContract,
|
|
181
|
+
data: callData,
|
|
182
|
+
gas: BigInt(200000),
|
|
183
|
+
type: "eip1559",
|
|
184
|
+
account: this.walletClient.account,
|
|
185
|
+
chain: this.walletClient.chain,
|
|
186
|
+
});
|
|
187
|
+
return signedTx;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Execute a signed intent through the gas station contract.
|
|
191
|
+
* Packs the execution data according to the delegate contract's expected format and
|
|
192
|
+
* submits it via the execution contract.
|
|
193
|
+
* Call this with a paymaster client to submit and pay for the transaction.
|
|
194
|
+
*/
|
|
195
|
+
async execute(intent) {
|
|
196
|
+
// Pack the execution data (signature, nonce, deadline, args)
|
|
197
|
+
const packedData = packExecutionData({
|
|
198
|
+
signature: intent.signature,
|
|
199
|
+
nonce: intent.nonce,
|
|
200
|
+
deadline: intent.deadline,
|
|
201
|
+
args: intent.callData,
|
|
202
|
+
});
|
|
203
|
+
// Call the unified execute function with explicit parameters
|
|
204
|
+
const txHash = await this.walletClient.sendTransaction({
|
|
205
|
+
to: this.executionContract,
|
|
206
|
+
data: encodeFunctionData({
|
|
207
|
+
abi: gasStationAbi,
|
|
208
|
+
functionName: "execute",
|
|
209
|
+
args: [
|
|
210
|
+
intent.eoaAddress,
|
|
211
|
+
intent.outputContract,
|
|
212
|
+
intent.ethAmount,
|
|
213
|
+
packedData,
|
|
214
|
+
],
|
|
215
|
+
}),
|
|
216
|
+
gas: BigInt(200000),
|
|
217
|
+
account: this.walletClient.account,
|
|
218
|
+
});
|
|
219
|
+
const receipt = await this.publicClient.waitForTransactionReceipt({
|
|
220
|
+
hash: txHash,
|
|
221
|
+
});
|
|
222
|
+
if (receipt.status !== "success") {
|
|
223
|
+
// Try to get the revert reason if available
|
|
224
|
+
const revertReason = await this.getRevertReason(txHash);
|
|
225
|
+
throw new Error(`Execution failed: ${revertReason || "Transaction reverted"}. ` +
|
|
226
|
+
`Gas used: ${receipt.gasUsed}/${receipt.cumulativeGasUsed}. ` +
|
|
227
|
+
`Transaction hash: ${txHash}`);
|
|
228
|
+
}
|
|
229
|
+
return {
|
|
230
|
+
txHash,
|
|
231
|
+
blockNumber: receipt.blockNumber,
|
|
232
|
+
gasUsed: receipt.gasUsed,
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Sign an approval then execution transaction for a signed intent (paymaster signs, doesn't send)
|
|
237
|
+
* This is useful for testing policies - the paymaster attempts to sign the execution
|
|
238
|
+
* but doesn't actually broadcast it to the network.
|
|
239
|
+
* Call this with a paymaster client to test if the paymaster can sign the execution.
|
|
240
|
+
*/
|
|
241
|
+
async signApproveThenExecution(intent) {
|
|
242
|
+
// Pack the execution data (signature, nonce, deadline, args)
|
|
243
|
+
const packedData = packExecutionData({
|
|
244
|
+
signature: intent.signature,
|
|
245
|
+
nonce: intent.nonce,
|
|
246
|
+
deadline: intent.deadline,
|
|
247
|
+
args: intent.callData,
|
|
248
|
+
});
|
|
249
|
+
// Encode the function call data
|
|
250
|
+
const callData = encodeFunctionData({
|
|
251
|
+
abi: gasStationAbi,
|
|
252
|
+
functionName: "approveThenExecute",
|
|
253
|
+
args: [
|
|
254
|
+
intent.eoaAddress,
|
|
255
|
+
intent.outputContract,
|
|
256
|
+
intent.ethAmount,
|
|
257
|
+
intent.erc20Address,
|
|
258
|
+
intent.spender,
|
|
259
|
+
intent.approveAmount,
|
|
260
|
+
packedData,
|
|
261
|
+
],
|
|
262
|
+
});
|
|
263
|
+
// Sign the transaction without sending it
|
|
264
|
+
const signedTx = await this.walletClient.signTransaction({
|
|
265
|
+
to: this.executionContract,
|
|
266
|
+
data: callData,
|
|
267
|
+
gas: BigInt(300000),
|
|
268
|
+
type: "eip1559",
|
|
269
|
+
account: this.walletClient.account,
|
|
270
|
+
chain: this.walletClient.chain,
|
|
271
|
+
});
|
|
272
|
+
return signedTx;
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Execute an approval then execution through the gas station contract.
|
|
276
|
+
* Atomically approves an ERC20 token and executes a transaction in a single call.
|
|
277
|
+
* Packs the execution data according to the delegate contract's expected format and
|
|
278
|
+
* submits it via the execution contract's approveThenExecute function.
|
|
279
|
+
* Call this with a paymaster client to submit and pay for the transaction.
|
|
280
|
+
*/
|
|
281
|
+
async approveThenExecute(intent) {
|
|
282
|
+
// Pack the execution data (signature, nonce, deadline, args)
|
|
283
|
+
const packedData = packExecutionData({
|
|
284
|
+
signature: intent.signature,
|
|
285
|
+
nonce: intent.nonce,
|
|
286
|
+
deadline: intent.deadline,
|
|
287
|
+
args: intent.callData,
|
|
288
|
+
});
|
|
289
|
+
// Call the approveThenExecute function with all parameters
|
|
290
|
+
const txHash = await this.walletClient.sendTransaction({
|
|
291
|
+
to: this.executionContract,
|
|
292
|
+
data: encodeFunctionData({
|
|
293
|
+
abi: gasStationAbi,
|
|
294
|
+
functionName: "approveThenExecute",
|
|
295
|
+
args: [
|
|
296
|
+
intent.eoaAddress,
|
|
297
|
+
intent.outputContract,
|
|
298
|
+
intent.ethAmount,
|
|
299
|
+
intent.erc20Address,
|
|
300
|
+
intent.spender,
|
|
301
|
+
intent.approveAmount,
|
|
302
|
+
packedData,
|
|
303
|
+
],
|
|
304
|
+
}),
|
|
305
|
+
gas: BigInt(300000),
|
|
306
|
+
account: this.walletClient.account,
|
|
307
|
+
});
|
|
308
|
+
const receipt = await this.publicClient.waitForTransactionReceipt({
|
|
309
|
+
hash: txHash,
|
|
310
|
+
});
|
|
311
|
+
if (receipt.status !== "success") {
|
|
312
|
+
// Try to get the revert reason if available
|
|
313
|
+
const revertReason = await this.getRevertReason(txHash);
|
|
314
|
+
throw new Error(`Approve then execute failed: ${revertReason || "Transaction reverted"}. ` +
|
|
315
|
+
`Gas used: ${receipt.gasUsed}/${receipt.cumulativeGasUsed}. ` +
|
|
316
|
+
`Transaction hash: ${txHash}`);
|
|
317
|
+
}
|
|
318
|
+
return {
|
|
319
|
+
txHash,
|
|
320
|
+
blockNumber: receipt.blockNumber,
|
|
321
|
+
gasUsed: receipt.gasUsed,
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* Sign a reimbursable execution transaction (paymaster signs, doesn't send).
|
|
326
|
+
* This is useful for testing policies - the paymaster attempts to sign the execution
|
|
327
|
+
* but doesn't actually broadcast it to the network.
|
|
328
|
+
* Call this with a paymaster client to test if the paymaster can sign the execution.
|
|
329
|
+
*/
|
|
330
|
+
async signReimbursableExecution(intent) {
|
|
331
|
+
// Pack the execution data (signature, nonce, deadline, args)
|
|
332
|
+
const packedExecutionData = packExecutionData({
|
|
333
|
+
signature: intent.signature,
|
|
334
|
+
nonce: intent.nonce,
|
|
335
|
+
deadline: intent.deadline,
|
|
336
|
+
args: intent.callData,
|
|
337
|
+
});
|
|
338
|
+
const callData = encodeFunctionData({
|
|
339
|
+
abi: reimbursableGasStationAbi,
|
|
340
|
+
functionName: "executeReturns",
|
|
341
|
+
args: [
|
|
342
|
+
intent.initialDepositUSDC,
|
|
343
|
+
intent.transactionGasLimitWei,
|
|
344
|
+
intent.sessionSignature,
|
|
345
|
+
intent.eoaAddress,
|
|
346
|
+
intent.outputContract,
|
|
347
|
+
intent.ethAmount,
|
|
348
|
+
packedExecutionData,
|
|
349
|
+
],
|
|
350
|
+
});
|
|
351
|
+
const signedTx = await this.walletClient.signTransaction({
|
|
352
|
+
to: this.reimbursableContract,
|
|
353
|
+
data: callData,
|
|
354
|
+
gas: BigInt(300000),
|
|
355
|
+
type: "eip1559",
|
|
356
|
+
account: this.walletClient.account,
|
|
357
|
+
chain: this.walletClient.chain,
|
|
358
|
+
});
|
|
359
|
+
return signedTx;
|
|
360
|
+
}
|
|
361
|
+
/**
|
|
362
|
+
* Execute with reimbursement through the reimbursable gas station contract.
|
|
363
|
+
* The EOA pays for gas in USDC rather than the paymaster covering the cost.
|
|
364
|
+
* The contract pulls initialDepositUSDC from the EOA, executes the transaction
|
|
365
|
+
* with a gas limit of transactionGasLimitWei, and refunds any unused USDC.
|
|
366
|
+
* Call this with a paymaster client to submit the transaction (paymaster only pays initial gas).
|
|
367
|
+
*/
|
|
368
|
+
async executeWithReimbursement(intent) {
|
|
369
|
+
// Pack the execution data (signature, nonce, deadline, args)
|
|
370
|
+
const packedExecutionData = packExecutionData({
|
|
371
|
+
signature: intent.signature,
|
|
372
|
+
nonce: intent.nonce,
|
|
373
|
+
deadline: intent.deadline,
|
|
374
|
+
args: intent.callData,
|
|
375
|
+
});
|
|
376
|
+
const txHash = await this.walletClient.sendTransaction({
|
|
377
|
+
to: this.reimbursableContract,
|
|
378
|
+
data: encodeFunctionData({
|
|
379
|
+
abi: reimbursableGasStationAbi,
|
|
380
|
+
functionName: "executeReturns",
|
|
381
|
+
args: [
|
|
382
|
+
intent.initialDepositUSDC,
|
|
383
|
+
intent.transactionGasLimitWei,
|
|
384
|
+
intent.sessionSignature,
|
|
385
|
+
intent.eoaAddress,
|
|
386
|
+
intent.outputContract,
|
|
387
|
+
intent.ethAmount,
|
|
388
|
+
packedExecutionData,
|
|
389
|
+
],
|
|
390
|
+
}),
|
|
391
|
+
gas: BigInt(300000),
|
|
392
|
+
account: this.walletClient.account,
|
|
393
|
+
});
|
|
394
|
+
const receipt = await this.publicClient.waitForTransactionReceipt({
|
|
395
|
+
hash: txHash,
|
|
396
|
+
});
|
|
397
|
+
if (receipt.status !== "success") {
|
|
398
|
+
// Try to get the revert reason if available
|
|
399
|
+
const revertReason = await this.getRevertReason(txHash);
|
|
400
|
+
throw new Error(`Reimbursable execution failed: ${revertReason || "Transaction reverted"}. ` +
|
|
401
|
+
`Gas used: ${receipt.gasUsed}/${receipt.cumulativeGasUsed}. ` +
|
|
402
|
+
`Transaction hash: ${txHash}`);
|
|
403
|
+
}
|
|
404
|
+
return {
|
|
405
|
+
txHash,
|
|
406
|
+
blockNumber: receipt.blockNumber,
|
|
407
|
+
gasUsed: receipt.gasUsed,
|
|
408
|
+
};
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
export { GasStationClient };
|
|
413
|
+
//# sourceMappingURL=gasStationClient.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gasStationClient.mjs","sources":["../src/gasStationClient.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;;MA6Ba,gBAAgB,CAAA;AAO3B,IAAA,WAAA,CAAY,MAAwB,EAAA;AAClC,QAAA,IAAI,CAAC,YAAY,GAAG,MAAM,CAAC,YAAY;AACvC,QAAA,IAAI,CAAC,YAAY,GAAG,0BAA0B,CAC5C,MAAM,CAAC,YAAY,CAAC,KAAK,EACzB,MAAM,CAAC,YAAY,CAAC,SAAS,CAAC,GAAI,CACnC;AACD,QAAA,IAAI,CAAC,gBAAgB;AACnB,YAAA,MAAM,CAAC,gBAAgB,IAAI,yBAAyB;AACtD,QAAA,IAAI,CAAC,iBAAiB;AACpB,YAAA,MAAM,CAAC,iBAAiB,IAAI,0BAA0B;AACxD,QAAA,IAAI,CAAC,oBAAoB;AACvB,YAAA,MAAM,CAAC,oBAAoB,IAAI,kCAAkC;IACrE;AAEA;;;;AAIG;IACH,MAAM,iBAAiB,CAAC,OAAgB,EAAA;QACtC,MAAM,aAAa,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,iBAAiB,CAAC;YAC9D,eAAe,EAAE,IAAI,CAAC,gBAAgB;AACtC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