crosslightning-evm
Advanced tools
Comparing version 3.3.1 to 3.3.2
@@ -1,2 +0,2 @@ | ||
import { providers, Wallet } from "ethers"; | ||
import { BigNumber, providers, Wallet } from "ethers"; | ||
import { Deferrable } from "@ethersproject/properties/lib"; | ||
@@ -19,3 +19,5 @@ export declare class OverridenStaticJsonRpcProvider extends providers.StaticJsonRpcProvider { | ||
private readonly boundTransactionListener; | ||
constructor(privateKey: string, rpcUrl: string, chainId: number, directory: string); | ||
readonly waitBeforeBump: number; | ||
readonly minFeeIncrease: BigNumber; | ||
constructor(privateKey: string, rpcUrl: string, chainId: number, directory: string, minFeeIncrease?: BigNumber, waitBeforeBumpMillis?: number); | ||
transactionListener(transaction: providers.TransactionReceipt): void; | ||
@@ -22,0 +24,0 @@ init(): Promise<void>; |
@@ -68,3 +68,3 @@ "use strict"; | ||
class EVMWallet extends ethers_1.Wallet { | ||
constructor(privateKey, rpcUrl, chainId, directory) { | ||
constructor(privateKey, rpcUrl, chainId, directory, minFeeIncrease, waitBeforeBumpMillis) { | ||
super(privateKey, new OverridenStaticJsonRpcProvider(rpcUrl, chainId)); | ||
@@ -78,2 +78,4 @@ this.pendingTxs = {}; | ||
this.boundTransactionListener = this.transactionListener.bind(this); | ||
this.minFeeIncrease = minFeeIncrease || MIN_FEE_INCREASE; | ||
this.waitBeforeBump = waitBeforeBumpMillis || WAIT_BEFORE_BUMP; | ||
} | ||
@@ -133,4 +135,5 @@ transactionListener(transaction) { | ||
const data = this.pendingTxs[nonceStr]; | ||
if (data.lastBumped < Date.now() - WAIT_BEFORE_BUMP) { | ||
if (data.lastBumped < Date.now() - this.waitBeforeBump) { | ||
const lastTx = data.txs[data.txs.length - 1]; | ||
console.log("Bump fee for tx: ", lastTx.hash); | ||
if (_gasPrice == null) | ||
@@ -140,4 +143,4 @@ _gasPrice = yield this.provider.getGasPrice(); | ||
const newTx = ethers_1.utils.shallowCopy(lastTx); | ||
if (feeDifference.lt(MIN_FEE_INCREASE)) { | ||
newTx.gasPrice = lastTx.gasPrice.add(MIN_FEE_INCREASE); | ||
if (feeDifference.lt(this.minFeeIncrease)) { | ||
newTx.gasPrice = lastTx.gasPrice.add(this.minFeeIncrease); | ||
} | ||
@@ -144,0 +147,0 @@ else { |
{ | ||
"name": "crosslightning-evm", | ||
"version": "3.3.1", | ||
"version": "3.3.2", | ||
"description": "EVM specific base implementation", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.js", |
@@ -81,3 +81,6 @@ import {BigNumber, providers, Transaction, UnsignedTransaction, utils, Wallet} from "ethers"; | ||
constructor(privateKey: string, rpcUrl: string, chainId: number, directory: string) { | ||
readonly waitBeforeBump: number; | ||
readonly minFeeIncrease: BigNumber; | ||
constructor(privateKey: string, rpcUrl: string, chainId: number, directory: string, minFeeIncrease?: BigNumber, waitBeforeBumpMillis?: number) { | ||
super(privateKey, new OverridenStaticJsonRpcProvider(rpcUrl, chainId)); | ||
@@ -87,2 +90,4 @@ this.directory = directory; | ||
this.boundTransactionListener = this.transactionListener.bind(this); | ||
this.minFeeIncrease = minFeeIncrease || MIN_FEE_INCREASE; | ||
this.waitBeforeBump = waitBeforeBumpMillis || WAIT_BEFORE_BUMP; | ||
} | ||
@@ -150,9 +155,10 @@ | ||
const data = this.pendingTxs[nonceStr]; | ||
if(data.lastBumped<Date.now()-WAIT_BEFORE_BUMP) { | ||
if(data.lastBumped<Date.now()-this.waitBeforeBump) { | ||
const lastTx = data.txs[data.txs.length-1]; | ||
console.log("Bump fee for tx: ", lastTx.hash); | ||
if(_gasPrice==null) _gasPrice = await this.provider.getGasPrice(); | ||
const feeDifference = _gasPrice.sub(lastTx.gasPrice); | ||
const newTx = utils.shallowCopy(lastTx); | ||
if(feeDifference.lt(MIN_FEE_INCREASE)) { | ||
newTx.gasPrice = lastTx.gasPrice.add(MIN_FEE_INCREASE); | ||
if(feeDifference.lt(this.minFeeIncrease)) { | ||
newTx.gasPrice = lastTx.gasPrice.add(this.minFeeIncrease); | ||
} else { | ||
@@ -159,0 +165,0 @@ newTx.gasPrice = _gasPrice; |
346585
8187