-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update integration tests and gas estimates logic (#34)
* feat: removed ethgasstation gas price provider * feat: add blocknative gas price provider using their api * feat: add basic high gas price provider * feat: export providers * feat: instatiates alpha router using new gas price providers * feat: changed USDT to EUROC for swap tests * only use USDC in gas model * remove console logs * update whale address * update integration tests * small optimization * remove comments * update gas price provider and tests * add blocknative api key * fix import * cleaning up * add more comments --------- Co-authored-by: Papa Smurf <chris@violet.co>
- Loading branch information
1 parent
1be9fc9
commit 21eac30
Showing
12 changed files
with
296 additions
and
394 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import { BigNumber } from '@ethersproject/bignumber'; | ||
import retry from 'async-retry'; | ||
import axios from 'axios'; | ||
|
||
import { log } from '../util/log'; | ||
|
||
import { GasPrice, IGasPriceProvider } from './gas-price-provider'; | ||
|
||
export type BlockNativeGasPriceResponse = { | ||
system: string; | ||
network: string; | ||
unit: string; | ||
maxPrice: number; | ||
currentBlockNumber: number; | ||
msSinceLastBlock: number; | ||
blockPrices: BlockPrice[]; | ||
estimatedBaseFees: { [block: string]: BaseFeeEstimate }; | ||
}; | ||
|
||
interface BlockPrice { | ||
blockNumber: number; | ||
estimatedTransactionCount: number; | ||
baseFeePerGas: number; | ||
estimatedPrices: PriceEstimate[]; | ||
} | ||
|
||
interface PriceEstimate { | ||
confidence: number; | ||
price: number; | ||
maxPriorityFeePerGas: number; | ||
maxFeePerGas: number; | ||
} | ||
|
||
interface BaseFeeEstimate { | ||
confidence: number; | ||
baseFee: number; | ||
} | ||
|
||
export class BlockNativeGasPriceProvider extends IGasPriceProvider { | ||
private apiKey: string; | ||
private url: string; | ||
constructor(apiKey: string) { | ||
super(); | ||
this.apiKey = apiKey; | ||
this.url = 'https://api.blocknative.com/gasprices/blockprices'; | ||
} | ||
|
||
public async getGasPrice(): Promise<GasPrice> { | ||
log.info(`About to get gas prices from gas station ${this.url}`); | ||
const response = await retry( | ||
async () => { | ||
return axios.get<BlockNativeGasPriceResponse>(this.url, { | ||
headers: { Authorization: `${this.apiKey}` }, | ||
}); | ||
}, | ||
{ retries: 1 } | ||
); | ||
|
||
const { data: gasPriceResponse, status } = response; | ||
|
||
if (status != 200) { | ||
log.error({ response }, `Unabled to get gas price from ${this.url}.`); | ||
|
||
throw new Error(`Unable to get gas price from ${this.url}`); | ||
} | ||
|
||
log.info( | ||
{ gasPriceResponse }, | ||
'Gas price response from API. About to parse "fast" to big number' | ||
); | ||
|
||
const baseFee = BigNumber.from( | ||
Math.ceil(gasPriceResponse.blockPrices[0]!.baseFeePerGas) | ||
); | ||
const priorityFee = BigNumber.from( | ||
Math.ceil( | ||
gasPriceResponse.blockPrices[0]!.estimatedPrices[0]! | ||
.maxPriorityFeePerGas | ||
) | ||
); | ||
|
||
log.info( | ||
`Base gas price in wei: ${baseFee} and max priority fee: ${priorityFee} as of block ${ | ||
gasPriceResponse.blockPrices[0]!.blockNumber | ||
}` | ||
); | ||
|
||
return { gasPriceWei: baseFee.add(priorityFee) }; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.