Skip to content

Commit d425fd9

Browse files
committed
use fee type
1 parent 3574117 commit d425fd9

File tree

2 files changed

+18
-15
lines changed

2 files changed

+18
-15
lines changed

packages/background/src/tx-executor/service.ts

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,7 @@ export class BackgroundTxExecutorService {
405405
const { signedTx } = await this.signTx(
406406
execution.vaultId,
407407
currentTx,
408+
execution.feeType,
408409
options?.env
409410
);
410411

@@ -465,6 +466,7 @@ export class BackgroundTxExecutorService {
465466
protected async signTx(
466467
vaultId: string,
467468
tx: BackgroundTx,
469+
feeType: ExecutionFeeType,
468470
env?: Env
469471
): Promise<{
470472
signedTx: string;
@@ -476,15 +478,16 @@ export class BackgroundTxExecutorService {
476478
}
477479

478480
if (tx.type === BackgroundTxType.EVM) {
479-
return this.signEvmTx(vaultId, tx, env);
481+
return this.signEvmTx(vaultId, tx, feeType, env);
480482
}
481483

482-
return this.signCosmosTx(vaultId, tx, env);
484+
return this.signCosmosTx(vaultId, tx, feeType, env);
483485
}
484486

485487
private async signEvmTx(
486488
vaultId: string,
487489
tx: EVMBackgroundTx,
490+
feeType: ExecutionFeeType,
488491
env?: Env
489492
): Promise<{
490493
signedTx: string;
@@ -528,7 +531,8 @@ export class BackgroundTxExecutorService {
528531
origin,
529532
evmInfo,
530533
signer,
531-
tx.txData
534+
tx.txData,
535+
feeType
532536
);
533537

534538
result = await this.keyRingEthereumService.signEthereumPreAuthorized(
@@ -561,6 +565,7 @@ export class BackgroundTxExecutorService {
561565
private async signCosmosTx(
562566
vaultId: string,
563567
tx: CosmosBackgroundTx,
568+
feeType: ExecutionFeeType,
564569
env?: Env
565570
): Promise<{
566571
signedTx: string;
@@ -711,7 +716,7 @@ export class BackgroundTxExecutorService {
711716
);
712717

713718
// TODO: fee token을 사용자가 설정한 것을 사용해야 함
714-
const { gasPrice } = await getCosmosGasPrice(chainInfo);
719+
const { gasPrice } = await getCosmosGasPrice(chainInfo, feeType);
715720
const fee = calculateCosmosStdFee(
716721
chainInfo.currencies[0],
717722
gasUsed,
@@ -1088,13 +1093,5 @@ export class BackgroundTxExecutorService {
10881093
this.recentTxExecutionMap.delete(id);
10891094
}
10901095
}
1091-
1092-
const entries = Array.from(this.recentTxExecutionMap.entries())
1093-
.filter(([, e]) => completedStatuses.includes(e.status))
1094-
.sort(([, a], [, b]) => a.timestamp - b.timestamp);
1095-
1096-
for (let i = 0; i < entries.length; i++) {
1097-
this.recentTxExecutionMap.delete(entries[i][0]);
1098-
}
10991096
}
11001097
}

packages/background/src/tx-executor/utils/evm.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,20 @@ import { EVMInfo } from "@keplr-wallet/types";
22
import { simpleFetch } from "@keplr-wallet/simple-fetch";
33
import { UnsignedTransaction } from "@ethersproject/transactions";
44
import { Dec } from "@keplr-wallet/unit";
5+
import { ExecutionFeeType } from "../types";
56

6-
const DEFAULT_MULTIPLIER = 1.25;
7+
const FEE_MULTIPLIERS: Record<ExecutionFeeType, number> = {
8+
low: 1.1,
9+
average: 1.25,
10+
high: 1.5,
11+
};
712

813
export async function fillUnsignedEVMTx(
914
origin: string,
1015
evmInfo: EVMInfo,
1116
signer: string,
12-
tx: UnsignedTransaction
17+
tx: UnsignedTransaction,
18+
feeType: ExecutionFeeType = "average"
1319
): Promise<UnsignedTransaction> {
1420
const getTransactionCountRequest = {
1521
jsonrpc: "2.0",
@@ -162,7 +168,7 @@ export async function fillUnsignedEVMTx(
162168
throw new Error("Failed to get baseFeePerGas to fill unsigned transaction");
163169
}
164170

165-
const multiplier = new Dec(DEFAULT_MULTIPLIER);
171+
const multiplier = new Dec(FEE_MULTIPLIERS[feeType]);
166172

167173
// Calculate maxFeePerGas = baseFeePerGas + maxPriorityFeePerGas
168174
const baseFeePerGasDec = new Dec(BigInt(latestBlock.baseFeePerGas));

0 commit comments

Comments
 (0)