Skip to content

Commit

Permalink
Rename recommendedGasPriceMultipler to baseGasPriceMultiplier
Browse files Browse the repository at this point in the history
  • Loading branch information
Siegrift committed Apr 1, 2024
1 parent 6273f33 commit 79e8778
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 20 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ Example of a scaling computation:

```js
// Parameters:
// - recommendedGasPriceMultiplier = 1.2
// - baseGasPriceMultiplier = 1.2
// - maxScalingMultiplier = 2
// - scalingWindow = 300
//
Expand All @@ -201,7 +201,7 @@ Example of a scaling computation:
1.2 + (2 - 1.2) * (2.5 / 5) = 1.6
```

###### `recommendedGasPriceMultiplier`
###### `baseGasPriceMultiplier`

The base multiplier used to compute the gas price. Used to multiply the latest (or sanitized) gas price.

Expand Down
2 changes: 1 addition & 1 deletion config/airseeker.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
}
},
"gasSettings": {
"recommendedGasPriceMultiplier": 1.5,
"baseGasPriceMultiplier": 1.5,
"sanitizationSamplingWindow": 900,
"sanitizationPercentile": 80,
"scalingWindow": 120,
Expand Down
2 changes: 1 addition & 1 deletion local-test-configuration/airseeker/airseeker.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
}
},
"gasSettings": {
"recommendedGasPriceMultiplier": 1.5,
"baseGasPriceMultiplier": 1.5,
"sanitizationSamplingWindow": 900,
"sanitizationPercentile": 80,
"scalingWindow": 120,
Expand Down
2 changes: 1 addition & 1 deletion src/config/schema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { chainsSchema, configSchema, deviationThresholdCoefficientSchema } from
import { interpolateSecrets } from './utils';

const gasSettings = {
recommendedGasPriceMultiplier: 1.5,
baseGasPriceMultiplier: 1.5,
sanitizationSamplingWindow: 900,
sanitizationPercentile: 80,
scalingWindow: 120,
Expand Down
8 changes: 4 additions & 4 deletions src/config/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,18 @@ export type Contracts = z.infer<typeof contractsSchema>;

export const gasSettingsSchema = z
.object({
recommendedGasPriceMultiplier: z.number().positive(),
baseGasPriceMultiplier: z.number().positive(),
sanitizationSamplingWindow: z.number().positive(),
sanitizationPercentile: z.number().positive(),
scalingWindow: z.number().positive(),
maxScalingMultiplier: z.number().positive(),
})
.superRefine((gasSettings, ctx) => {
if (gasSettings.recommendedGasPriceMultiplier > gasSettings.maxScalingMultiplier) {
if (gasSettings.baseGasPriceMultiplier > gasSettings.maxScalingMultiplier) {
ctx.addIssue({
code: 'custom',
message: 'recommendedGasPriceMultiplier must be less than or equal to maxScalingMultiplier.',
path: ['recommendedGasPriceMultiplier'],
message: 'baseGasPriceMultiplier must be less than or equal to maxScalingMultiplier.',
path: ['baseGasPriceMultiplier'],
});
}

Expand Down
6 changes: 3 additions & 3 deletions src/gas-price/gas-price.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ describe(getRecommendedGasPrice.name, () => {

const gasPrice = getRecommendedGasPrice(chainId, providerName, sponsorWalletAddress);

expect(gasPrice).toStrictEqual(ethers.parseUnits('14.1', 'gwei')); // The price is multiplied by the recommendedGasPriceMultiplier.
expect(gasPrice).toStrictEqual(ethers.parseUnits('14.1', 'gwei')); // The price is multiplied by the baseGasPriceMultiplier.
expect(logger.warn).toHaveBeenCalledTimes(1);
expect(logger.warn).toHaveBeenNthCalledWith(1, 'Sanitizing gas price.', {
gasPrice: '10000000000',
Expand All @@ -186,7 +186,7 @@ describe(getRecommendedGasPrice.name, () => {

const gasPrice = getRecommendedGasPrice(chainId, providerName, sponsorWalletAddress);

expect(gasPrice).toStrictEqual(ethers.parseUnits('15', 'gwei')); // The price is multiplied by the recommendedGasPriceMultiplier.
expect(gasPrice).toStrictEqual(ethers.parseUnits('15', 'gwei')); // The price is multiplied by the baseGasPriceMultiplier.
expect(logger.warn).toHaveBeenCalledTimes(1);
expect(logger.warn).toHaveBeenNthCalledWith(
1,
Expand Down Expand Up @@ -215,7 +215,7 @@ describe(getRecommendedGasPrice.name, () => {
const gasPrice = getRecommendedGasPrice(chainId, providerName, sponsorWalletAddress);

expect(latestStoredGasPrice).toStrictEqual(ethers.parseUnits('7.1', 'gwei'));
expect(gasPrice).toStrictEqual(ethers.parseUnits('10.65', 'gwei')); // The price is multiplied by the recommendedGasPriceMultiplier.
expect(gasPrice).toStrictEqual(ethers.parseUnits('10.65', 'gwei')); // The price is multiplied by the baseGasPriceMultiplier.
expect(logger.warn).toHaveBeenCalledTimes(0);
});

Expand Down
14 changes: 7 additions & 7 deletions src/gas-price/gas-price.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,19 +86,19 @@ export const getPercentile = (percentile: number, array: bigint[]) => {

/**
* Calculates the multiplier to use for pending transactions.
* @param recommendedGasPriceMultiplier
* @param baseGasPriceMultiplier
* @param maxScalingMultiplier
* @param lag
* @param scalingWindow
*/
export const calculateScalingMultiplier = (
recommendedGasPriceMultiplier: number,
baseGasPriceMultiplier: number,
maxScalingMultiplier: number,
lag: number,
scalingWindow: number
) =>
Math.min(
recommendedGasPriceMultiplier + (maxScalingMultiplier - recommendedGasPriceMultiplier) * (lag / scalingWindow),
baseGasPriceMultiplier + (maxScalingMultiplier - baseGasPriceMultiplier) * (lag / scalingWindow),
maxScalingMultiplier
);

Expand Down Expand Up @@ -147,7 +147,7 @@ export const getRecommendedGasPrice = (chainId: string, providerName: string, sp
const { gasPrices, sponsorLastUpdateTimestamp } = state.gasPrices[chainId]![providerName]!;
const {
gasSettings: {
recommendedGasPriceMultiplier,
baseGasPriceMultiplier,
sanitizationPercentile,
sanitizationSamplingWindow,
scalingWindow,
Expand All @@ -172,7 +172,7 @@ export const getRecommendedGasPrice = (chainId: string, providerName: string, sp
if (lastUpdateTimestamp) {
const pendingPeriod = Math.floor(Date.now() / 1000) - lastUpdateTimestamp;
const scalingMultiplier = calculateScalingMultiplier(
recommendedGasPriceMultiplier,
baseGasPriceMultiplier,
maxScalingMultiplier,
pendingPeriod,
scalingWindow
Expand Down Expand Up @@ -212,8 +212,8 @@ export const getRecommendedGasPrice = (chainId: string, providerName: string, sp
gasPrice: latestGasPrice.toString(),
percentileGasPrice: percentileGasPrice.toString(),
});
return multiplyBigNumber(percentileGasPrice, recommendedGasPriceMultiplier);
return multiplyBigNumber(percentileGasPrice, baseGasPriceMultiplier);
}

return multiplyBigNumber(latestGasPrice, recommendedGasPriceMultiplier);
return multiplyBigNumber(latestGasPrice, baseGasPriceMultiplier);
};
2 changes: 1 addition & 1 deletion test/fixtures/mock-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const generateTestConfig = (): Config => ({
},
providers: { hardhat: { url: 'http://127.0.0.1:8545' } },
gasSettings: {
recommendedGasPriceMultiplier: 1.5,
baseGasPriceMultiplier: 1.5,
sanitizationPercentile: 80,
sanitizationSamplingWindow: 900,
maxScalingMultiplier: 2,
Expand Down

0 comments on commit 79e8778

Please sign in to comment.