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

Fxpool fix oracle conversion for TXAU and TXAG #584

Merged
merged 3 commits into from
Apr 10, 2024

Conversation

andreiashu
Copy link
Contributor

Description

This fix is a follow-up of PR #575 Multiple Quote Tokens support for FXPools: FXPoolDeployerTracker

For some RWA tokens (metal tokens like Aurus: TXAU, TXAG), the token represents a gram unit while the Chainlink Aggregator returns the price in $ / ounce. For example: each TXAU token represents a gram of Gold while the Chainlink Aggregator for XAU will return the price in ounces. Because of this we added an oracle adaptor contract in front of said aggregator. We found a workaround so that the subgraph code can dynamically pickup on such oracle adapter contracts. Moving forward we will be using an AggregatorConverter that exposes a DIVISOR and DECIMALS public state variables. With these 2 parameters the subgraph code can perform the required conversion for the AnswerUpdated event that is emitted directly by the Chainlink Aggregator.

Additionally, we spotted an older bug in our code whereby if one of the tokens in a pool happened to not have an existing oracle associated with it, the code would return thus exiting the loop and missing out on subsequent valid tokens / oracles. The way this is reflected in the subgraph results that the TXAU token would return a latestFXPrice of null. We only noticed this bug in the fork/testing environment, production doesn't seem to have it (possibly because prod gets re-synced from an earlier block).

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Dependency changes
  • Code refactor / cleanup
  • Documentation or wording changes
  • Other

How should this be tested?

We've deployed the changes over to our balancer subgraph polygon clone (trimmed down version, starting from block 54559454 ): https://thegraph.com/hosted-service/subgraph/xave-finance/balancer-v2-polygon

Simply run the following query:

query MyQuery {
  tokens(first: 100, where: {symbol_in: ["TXAU", "TXAG"]}) {
    address
    latestFXPrice
    fxOracleDecimals
    decimals
    name
    symbol
  }
}

The return should looks like the one below. Both Aurus tokens show the correct price / gram.

{
  "data": {
    "tokens": [
      {
        "address": "0x57fcbd6503c8be3b1abad191bc7799ef414a5b31",
        "latestFXPrice": "0.89880627",
        "fxOracleDecimals": 8,
        "decimals": 18,
        "name": "tSILVER",
        "symbol": "TXAG"
      },
      {
        "address": "0xa6da8c8999c094432c77e7d318951d34019af24b",
        "latestFXPrice": "75.01219284",
        "fxOracleDecimals": 8,
        "decimals": 18,
        "name": "tGOLD",
        "symbol": "TXAU"
      }
    ]
  }
}

The current production code on polygon returns the price in $ / ounce which is incorrect:

{
  "data": {
    "tokens": [
      {
        "address": "0x57fcbd6503c8be3b1abad191bc7799ef414a5b31",
        "latestFXPrice": "27.7",
        "fxOracleDecimals": 8,
        "decimals": 18,
        "name": "tSILVER",
        "symbol": "TXAG"
      },
      {
        "address": "0xa6da8c8999c094432c77e7d318951d34019af24b",
        "latestFXPrice": "2327.83",
        "fxOracleDecimals": 8,
        "decimals": 18,
        "name": "tGOLD",
        "symbol": "TXAU"
      }
    ]
  }
}

Checklist:

  • I have performed a self-review of my own code
  • I have requested at least 1 review (If the PR is significant enough, use best judgement here)
  • I have commented my code where relevant, particularly in hard-to-understand areas

dev -> master

  • I have checked that all beta deployments have synced
  • I have checked that the earliest block in the polygon pruned deployment is block, date/time
    • The earliest block is more than 24 hours old
  • I have checked that core metrics are the same in the beta and production deployments

Merges to dev

  • I have checked that the graft base is not a pruned deployment

@andreiashu andreiashu marked this pull request as ready for review April 10, 2024 13:41
@andreiashu andreiashu requested a review from mendesfabio as a code owner April 10, 2024 13:41
@andreiashu andreiashu changed the title Fxpool fix oracle conversion Fxpool fix oracle conversion for TXAU and TXAG Apr 10, 2024
@mendesfabio mendesfabio merged commit 4465f5b into balancer:dev Apr 10, 2024
0 of 4 checks passed
@mendesfabio mendesfabio mentioned this pull request Apr 15, 2024
7 tasks
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.

2 participants