Skip to content

Commit 0fb1556

Browse files
joaquim-vergesfarhanW3arcoravenwarengonzaga
authored
add gas to txOverrides (#477)
* add gas to txOverrides * Update: Completed Tx-Override (#506) * CICD for beta-nightly image (#481) * Updated Packages + UserOp Confirmation flow updated (#479) * Updated Packages + UserOp Confirmation flow updated * wallets sdk updated * fix: missing querystring + description upd (#486) * Added querystring to fastify route (#487) * fix: reject deprecated chains (#488) * chore: Allow cancelling txs that already errored (#491) * chore: Allow cancelling txs that already errored * clean up response * naming * update cancelledAt * fix: Cancel tx if populating a tx to retry fails (#493) * fix: Cancel tx if populating a tx to retry fails * ensure cancel uses high enough gas * fix build * combine prepare + send flows again * updates to GH flow, to use branch (#484) * updates to GH flow, to use branch * removed prelease incorrect tag * upds * got back tag creation check * upds * comments updated * final upds to handle the flow * Updated to use release::create for CI/CD image build/push flow * Updates to GH workflow to not push to if not release not from main (#495) * feat(experimental): Keypair auth (#494) * reorganize helper file * wip * support keypair auth * fix unit tests * return error messages for keypair auth errors * Don't catch JsonWebToken errors * catch access token * move public keys to db * fix: add crud endpoints * wip * add algorithm * add feature envvar * handle each jwt type separately * rename * remove expiration limit * Fix: Deploy Published Contract Flow (#499) * Updated Deploy Published Contract Flow + ProcessTx * removed commented lines * Updates * chore: add updated template for the railway (#490) * chore: add updated template for the railway Signed-off-by: Waren Gonzaga <opensource@warengonzaga.com> * chore: remove referral code Signed-off-by: Waren Gonzaga <opensource@warengonzaga.com> --------- Signed-off-by: Waren Gonzaga <opensource@warengonzaga.com> * Build fixes (#500) * Fix for Issue 502 (#505) * Added tx overrides for EOA + AA --------- Signed-off-by: Waren Gonzaga <opensource@warengonzaga.com> Co-authored-by: Phillip Ho <arcoraven@gmail.com> Co-authored-by: Waren Gonzaga <github@warengonzaga.com> * updates to help with better readability --------- Signed-off-by: Waren Gonzaga <opensource@warengonzaga.com> Co-authored-by: farhanW3 <farhan@thirdweb.com> Co-authored-by: farhanW3 <132962163+farhanW3@users.noreply.github.com> Co-authored-by: Phillip Ho <arcoraven@gmail.com> Co-authored-by: Waren Gonzaga <github@warengonzaga.com>
1 parent 3115375 commit 0fb1556

File tree

5 files changed

+77
-7
lines changed

5 files changed

+77
-7
lines changed

src/db/transactions/queueTx.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ interface QueueTxParams {
1515
deployedContractType?: string;
1616
simulateTx?: boolean;
1717
idempotencyKey?: string;
18+
txOverrides?: {
19+
gas?: string;
20+
maxFeePerGas?: string;
21+
maxPriorityFeePerGas?: string;
22+
};
1823
}
1924

2025
export const queueTx = async ({
@@ -26,6 +31,7 @@ export const queueTx = async ({
2631
deployedContractType,
2732
simulateTx,
2833
idempotencyKey,
34+
txOverrides,
2935
}: QueueTxParams) => {
3036
// TODO: We need a much safer way of detecting if the transaction should be a user operation
3137
const isUserOp = !!(tx.getSigner as ERC4337EthersSigner).erc4337provider;
@@ -38,6 +44,7 @@ export const queueTx = async ({
3844
deployedContractType: deployedContractType,
3945
data: tx.encode(),
4046
value: BigNumber.from(await tx.getValue()).toHexString(),
47+
...txOverrides,
4148
};
4249

4350
if (isUserOp) {

src/db/transactions/queueTxRaw.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ type QueueTxRawParams = Omit<
2525
pgtx?: PrismaTransaction;
2626
simulateTx?: boolean;
2727
idempotencyKey?: string;
28+
gas?: string;
2829
};
2930

3031
export const queueTxRaw = async ({
@@ -60,6 +61,8 @@ export const queueTxRaw = async ({
6061
target: tx.target?.toLowerCase(),
6162
signerAddress: tx.signerAddress?.toLowerCase(),
6263
accountAddress: tx.accountAddress?.toLowerCase(),
64+
gasLimit: tx.gas,
65+
gas: undefined,
6366
};
6467

6568
let txRow: Transactions;

src/server/routes/contract/write/write.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,22 @@ export async function writeToContract(fastify: FastifyInstance) {
8585
walletAddress,
8686
accountAddress,
8787
});
88-
const tx = await contract.prepare(functionName, args, txOverrides);
88+
const tx = contract.prepare(functionName, args, {
89+
value: txOverrides?.value,
90+
gasLimit: txOverrides?.gas,
91+
maxFeePerGas: txOverrides?.maxFeePerGas,
92+
maxPriorityFeePerGas: txOverrides?.maxPriorityFeePerGas,
93+
});
8994

9095
const queueId = await queueTx({
9196
tx,
9297
chainId,
9398
simulateTx,
9499
extension: "none",
95100
idempotencyKey,
101+
txOverrides: {
102+
...txOverrides,
103+
},
96104
});
97105

98106
reply.status(StatusCodes.OK).send({

src/server/schemas/txOverrides.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,28 @@ export const txOverrides = Type.Object({
55
Type.Object({
66
value: Type.Optional(
77
Type.String({
8-
examples: ["0"],
8+
examples: ["10000000000"],
99
description: "Amount of native currency to send",
1010
}),
1111
),
12+
gas: Type.Optional(
13+
Type.String({
14+
examples: ["530000"],
15+
description: "Gas limit for the transaction",
16+
}),
17+
),
18+
maxFeePerGas: Type.Optional(
19+
Type.String({
20+
examples: ["1000000000"],
21+
description: "Maximum fee per gas",
22+
}),
23+
),
24+
maxPriorityFeePerGas: Type.Optional(
25+
Type.String({
26+
examples: ["1000000000"],
27+
description: "Maximum priority fee per gas",
28+
}),
29+
),
1230
}),
1331
),
1432
});

src/worker/tasks/processTx.ts

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,27 @@ export const processTx = async () => {
171171
...gasOverrides,
172172
});
173173

174-
// TODO: We need to target specific cases
175-
// Bump gas limit to avoid occasional out of gas errors
176-
txRequest.gasLimit = txRequest.gasLimit
177-
? BigNumber.from(txRequest.gasLimit).mul(120).div(100)
178-
: undefined;
174+
// Gas limit override
175+
if (tx.gasLimit) {
176+
txRequest.gasLimit = BigNumber.from(tx.gasLimit);
177+
} else {
178+
// TODO: We need to target specific cases
179+
// Bump gas limit to avoid occasional out of gas errors
180+
txRequest.gasLimit = txRequest.gasLimit
181+
? BigNumber.from(txRequest.gasLimit).mul(120).div(100)
182+
: undefined;
183+
}
184+
185+
// Gas price overrides
186+
if (tx.maxFeePerGas) {
187+
txRequest.maxFeePerGas = BigNumber.from(tx.maxFeePerGas);
188+
}
189+
190+
if (tx.maxPriorityFeePerGas) {
191+
txRequest.maxPriorityFeePerGas = BigNumber.from(
192+
tx.maxPriorityFeePerGas,
193+
);
194+
}
179195

180196
const signature = await signer.signTransaction(txRequest);
181197
const rpcRequest = {
@@ -378,6 +394,24 @@ export const processTx = async () => {
378394
nonce,
379395
},
380396
);
397+
398+
// Temporary fix untill SDK allows us to do this
399+
if (tx.gasLimit) {
400+
unsignedOp.callGasLimit = BigNumber.from(tx.gasLimit);
401+
unsignedOp.paymasterAndData = "0x";
402+
const DUMMY_SIGNATURE =
403+
"0xfffffffffffffffffffffffffffffff0000000000000000000000000000000007aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1c";
404+
unsignedOp.signature = DUMMY_SIGNATURE;
405+
const paymasterResult =
406+
await signer.smartAccountAPI.paymasterAPI.getPaymasterAndData(
407+
unsignedOp,
408+
);
409+
const paymasterAndData = paymasterResult.paymasterAndData;
410+
if (paymasterAndData && paymasterAndData !== "0x") {
411+
unsignedOp.paymasterAndData = paymasterAndData;
412+
}
413+
}
414+
381415
const userOp = await signer.smartAccountAPI.signUserOp(unsignedOp);
382416
const userOpHash = await signer.smartAccountAPI.getUserOpHash(
383417
userOp,

0 commit comments

Comments
 (0)