Skip to content

Commit

Permalink
Move rpc call into nextNonce
Browse files Browse the repository at this point in the history
It isn't necessary to slow down use of workflowUtils by calling this method
  • Loading branch information
peachbits committed Nov 5, 2024
1 parent 32f1c43 commit 7ad18ee
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,13 @@ export const makeEthereumKilnAdapter = (policyConfig: StakePolicyConfig<Ethereum
const walletSigner = new EdgeWalletSigner(wallet, provider)
const walletAddress = await walletSigner.getAddress()

let txCount: number = await walletSigner.getTransactionCount('pending')
const nextNonce = (): number => txCount++
let txCount: number | undefined
const nextNonce = async (): Promise<number> => {
if (txCount == null) {
txCount = await walletSigner.getTransactionCount('pending')
}
return txCount++
}

const feeData = await provider.getFeeData()
const maxFeePerGas = feeData.maxFeePerGas !== null ? feeData.maxFeePerGas : undefined
Expand Down Expand Up @@ -108,7 +113,7 @@ export const makeEthereumKilnAdapter = (policyConfig: StakePolicyConfig<Ethereum
gasLimit: '500000',
maxFeePerGas,
maxPriorityFeePerGas,
nonce: nextNonce()
nonce: await nextNonce()
})

return await prepareChangeQuote(walletSigner, tx, allocations)
Expand All @@ -121,7 +126,7 @@ export const makeEthereumKilnAdapter = (policyConfig: StakePolicyConfig<Ethereum
gasLimit: '250000', // Typically uses 190000-225000 gas
maxFeePerGas,
maxPriorityFeePerGas,
nonce: nextNonce(),
nonce: await nextNonce(),
value: requestNativeAmount
})

Expand All @@ -144,7 +149,7 @@ export const makeEthereumKilnAdapter = (policyConfig: StakePolicyConfig<Ethereum
gasLimit: '500000',
maxFeePerGas,
maxPriorityFeePerGas,
nonce: nextNonce()
nonce: await nextNonce()
})

const allocations: QuoteAllocation[] = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,13 @@ export const makeGlifInfinityPoolAdapter = (policyConfig: StakePolicyConfig<Glif
const walletSigner = new EdgeWalletSigner(wallet, provider)
const walletAddress = await walletSigner.getAddress()

let txCount: number = await walletSigner.getTransactionCount('pending')
const nextNonce = (): number => txCount++
let txCount: number | undefined
const nextNonce = async (): Promise<number> => {
if (txCount == null) {
txCount = await walletSigner.getTransactionCount('pending')
}
return txCount++
}

const feeData = await provider.getFeeData()
const maxFeePerGas = feeData.maxFeePerGas !== null ? feeData.maxFeePerGas : undefined
Expand Down Expand Up @@ -109,7 +114,7 @@ export const makeGlifInfinityPoolAdapter = (policyConfig: StakePolicyConfig<Glif
value: requestNativeAmount,
maxFeePerGas,
maxPriorityFeePerGas,
nonce: nextNonce(),
nonce: await nextNonce(),
customData: {
metadata: {
name: metadataName,
Expand Down Expand Up @@ -152,7 +157,7 @@ export const makeGlifInfinityPoolAdapter = (policyConfig: StakePolicyConfig<Glif
await poolTokenContract.connect(walletSigner).populateTransaction.approve(simpleRampContract.address, expectedLiquidityAmount, {
maxFeePerGas,
maxPriorityFeePerGas,
nonce: nextNonce(),
nonce: await nextNonce(),
customData: {
metadata: {
name: metadataName,
Expand All @@ -170,7 +175,7 @@ export const makeGlifInfinityPoolAdapter = (policyConfig: StakePolicyConfig<Glif
gasLimit: 250000000,
maxFeePerGas,
maxPriorityFeePerGas,
nonce: nextNonce(),
nonce: await nextNonce(),
customData: {
metadata: {
name: metadataName,
Expand Down

0 comments on commit 7ad18ee

Please sign in to comment.