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

Create an IBT entity to get more IBT Rate precision #156

Merged
merged 2 commits into from
May 27, 2024

Conversation

jeanchambras
Copy link
Contributor

@jeanchambras jeanchambras commented May 23, 2024

  • Create a new IBT entity that will udpate the IBT rate and referenced in all PT
  • This IBT entity is updated upon each IBT transfer BUT we don't index / store each transfer because this would be too large and costly to index all these entitites. The only thing we modify is the ibtRate
  • Some optimisations are done to avoid some eth_call with assets

We will then in the app fetch the IBTRate from the IBT entity as this value will be the most updated

@jeanchambras jeanchambras requested a review from matstyler May 23, 2024 12:06
@GaspardPeduzzi GaspardPeduzzi linked an issue May 23, 2024 that may be closed by this pull request
schema.graphql Outdated Show resolved Hide resolved
schema.graphql Outdated Show resolved Hide resolved
src/entities/ERC20.ts Show resolved Hide resolved
let convertToAssets = getIBTRate(Address.fromBytes(ibtAddress))
ibt.convertToAssetsUnit = convertToAssets
const UNDERLYING_UNIT = getUnderlyingUnit(Address.fromBytes(ibtAddress))
ibt.lastIBTRate = convertToAssets.divDecimal(UNDERLYING_UNIT.toBigDecimal())
Copy link
Contributor

Choose a reason for hiding this comment

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

why do we need underlying unit to calculate ibt rate?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the definition of the IBT Rate it is the exchange rate between the IBT and the underlying given in underlying decimals. Here we give the raw result and also a precomputation of the rate for readability, and for different use cases where we don't need a BigInt. For some computation in the app the IBT Rate is used with a BigInt computation and is thus faster to already have a BigInt and reduce to a float at the end of the computation

@jeanchambras jeanchambras force-pushed the feat/isolated-ibtrate branch from f04fcbf to 7a1ede6 Compare May 24, 2024 14:51
@jeanchambras jeanchambras requested a review from matstyler May 24, 2024 15:42
@jeanchambras jeanchambras merged commit 7d7b3c4 into master May 27, 2024
2 checks passed
@jeanchambras jeanchambras deleted the feat/isolated-ibtrate branch May 27, 2024 16:01
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.

IBTRates should be updated on IBT transfers
2 participants