Skip to content

Commit

Permalink
chore: added custom gas coeff
Browse files Browse the repository at this point in the history
  • Loading branch information
bangjelkoski committed Nov 16, 2023
1 parent 006ad40 commit 740b38e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ interface MsgBroadcasterLocalOptions {
ethereumChainId?: EthereumChainId
simulateTx?: boolean
gasBufferCoefficient?: number
increaseSequenceLocally?: boolean
}

/**
Expand All @@ -73,8 +72,6 @@ export class MsgBroadcasterLocal {

public simulateTx: boolean = false

public increaseSequenceLocally: boolean = false

public baseAccount: BaseAccount | undefined = undefined

public gasBufferCoefficient = 1.1
Expand All @@ -86,7 +83,6 @@ export class MsgBroadcasterLocal {
const endpoints = getNetworkEndpoints(options.network)

this.simulateTx = options.simulateTx || false
this.increaseSequenceLocally = options.increaseSequenceLocally || false
this.chainId = networkInfo.chainId
this.gasBufferCoefficient = options.gasBufferCoefficient || 1.1
this.ethereumChainId =
Expand Down Expand Up @@ -312,7 +308,7 @@ export class MsgBroadcasterLocal {
}

private async getAccountDetails() {
if (this.baseAccount && this.increaseSequenceLocally) {
if (this.baseAccount) {
return this.baseAccount.toAccountDetails()
}

Expand All @@ -327,8 +323,6 @@ export class MsgBroadcasterLocal {
}

private async incrementTxCount() {
if (this.increaseSequenceLocally) {
this.txCount += 1
}
this.txCount += 1
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ interface MsgBroadcasterWithPkOptions {
ethereumChainId?: EthereumChainId
simulateTx?: boolean
loggingEnabled?: boolean
gasBufferCoefficient?: number
}

/**
Expand All @@ -76,10 +77,13 @@ export class MsgBroadcasterWithPk {

public loggingEnabled: boolean = false

public gasBufferCoefficient: number = 1.1

constructor(options: MsgBroadcasterWithPkOptions) {
const networkInfo = getNetworkInfo(options.network)
const endpoints = getNetworkEndpoints(options.network)

this.gasBufferCoefficient = options.gasBufferCoefficient || 1.1
this.simulateTx = options.simulateTx || false
this.loggingEnabled = options.loggingEnabled || false
this.chainId = networkInfo.chainId
Expand Down Expand Up @@ -212,10 +216,10 @@ export class MsgBroadcasterWithPk {
*
* If we want to simulate the transaction we set the
* gas limit based on the simulation and add a small multiplier
* to be safe (factor of 1.1)
* to be safe (factor of 1.1 (or user specified))
*/
private async getTxWithStdFee(args: CreateTransactionArgs) {
const { simulateTx } = this
const { simulateTx, gasBufferCoefficient } = this

if (!simulateTx) {
return createTransaction(args)
Expand All @@ -229,7 +233,9 @@ export class MsgBroadcasterWithPk {

const stdGasFee = getStdFee({
...args.fee,
gas: new BigNumberInBase(result.gasInfo.gasUsed).times(1.1).toFixed(),
gas: new BigNumberInBase(result.gasInfo.gasUsed)
.times(gasBufferCoefficient)
.toFixed(),
})

return createTransaction({ ...args, fee: stdGasFee })
Expand Down Expand Up @@ -313,6 +319,7 @@ export class MsgBroadcasterWithPk {
privateKey.toBech32(),
)
const baseAccount = BaseAccount.fromRestApi(accountDetailsResponse)

return baseAccount.toAccountDetails()
}

Expand Down

0 comments on commit 740b38e

Please sign in to comment.