Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gas price #26

Merged
merged 41 commits into from
Oct 26, 2023
Merged

Gas price #26

merged 41 commits into from
Oct 26, 2023

Conversation

vponline
Copy link
Contributor

@vponline vponline commented Oct 9, 2023

Closes #10

@vponline vponline marked this pull request as draft October 9, 2023 14:04
@vponline vponline requested a review from aquarat October 9, 2023 14:04
@vponline vponline marked this pull request as ready for review October 12, 2023 10:14
Copy link
Collaborator

@aquarat aquarat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM :)

src/config/schema.ts Outdated Show resolved Hide resolved
src/gas-price/gas-price.ts Outdated Show resolved Hide resolved
src/gas-price/gas-price.ts Outdated Show resolved Hide resolved
src/gas-price/gas-price.ts Outdated Show resolved Hide resolved
@vponline vponline requested a review from aquarat October 23, 2023 07:01
@vponline
Copy link
Contributor Author

Please re-review based on the new spec 😄

The changes include:

  • No separate interval for the gas collector, it will be ran within the main loop
  • Separate logic to fetch new price and clear old prices
  • Separate logic to fetch new price and calculate airseekerV2 price (with scaling and sanitization)
  • Checking for pending transactions based on datafeedId:value mapping
  • Added function to clear datafeedId:value mapping

Copy link
Collaborator

@Siegrift Siegrift left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The gas oracle implementation looks good to me, but I think the integration with the main loop will make some functions unused (but we can remove them then).

.github/workflows/main.yml Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
src/gas-price/gas-price.test.ts Outdated Show resolved Hide resolved
src/gas-price/gas-price.ts Outdated Show resolved Hide resolved
src/gas-price/gas-price.ts Outdated Show resolved Hide resolved
test/e2e/gas-price.feature.ts Show resolved Hide resolved
src/gas-price/gas-price.ts Outdated Show resolved Hide resolved
src/gas-price/gas-price.ts Show resolved Hide resolved
src/gas-price/gas-price.ts Show resolved Hide resolved
src/gas-price/gas-price.ts Outdated Show resolved Hide resolved
});

// Get the provider recommended gas price
const goGasPrice = await go(async () => provider.getGasPrice(), { retries: 1, attemptTimeoutMs: 2000 });
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how I feel about retrying the get gas price call. It seems a bit arbitrary to me.

Copy link
Contributor Author

@vponline vponline Oct 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Errors should probably be handled at the getAirseekerV2ProviderRecommendedGasPrice level in the main loop, with no go around the getGasPrice if we don't want to retry there.

getGasPrice could even be called outside of this scope of these functions (in the main loop) and the value passed to these functions, making them all synchronous if we wanted? I don't have a big preference either way since it's pretty simple.


export const gasPriceStore: Record<string, Record<string, GasState>> = {};

export const initializeGasStore = (chainId: string, providerName: string) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should have just a single state, so I'd move merge this logic with src/state.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, that was quite a refactor 😄

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hehe, we can plug in https://immerjs.github.io/immer/ to help simplify this. Feel free to create an issue.

if (
lastDataFeedValue &&
newDataFeedUpdateOnChainValues &&
lastDataFeedValue?.value === newDataFeedUpdateOnChainValues.newDataFeedValue.value &&
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this slack comment I keep wondering about this.

We will be making new transactions all the time (since the singed data changes asynchronously) and this will not track pending txs correctly. I do not see any other way except relying on wallet nonces or awaiting the transaction promise.

Copy link
Collaborator

@Siegrift Siegrift Oct 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the important part is that if the on-chain value changes there had to be an update. If that's only what we care about then the logic is sound.

I was afraid that we don't know how old is the timestamp (of the value that caused the update), but now that I think about it we don't care about that.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really like these test btw.

Copy link
Collaborator

@Siegrift Siegrift left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙏 Thanks for the discussions and making this work.

With https://github.com/api3dao/airseeker-v2/pull/26/files#r1372062174 I think the logic is now clear to me.

@vponline vponline merged commit 03284c2 into main Oct 26, 2023
4 checks passed
@vponline vponline deleted the gas-price branch October 26, 2023 06:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement recommended gas price
3 participants