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

Uniswap-v3 twap historical data inaccurate. #754

Open
Siddharth2207 opened this issue Aug 5, 2024 · 0 comments
Open

Uniswap-v3 twap historical data inaccurate. #754

Siddharth2207 opened this issue Aug 5, 2024 · 0 comments
Assignees

Comments

@Siddharth2207
Copy link
Contributor

  • Twap data for historical blocks does not match the data generate from the forge test. Twap value is closer to the current spot price at the block, rather then average price for a twap duration.
  • Rainlang Source:
#BackTest

networks:
  base-community: 
    rpc: https://base.llamarpc.com
    chain-id: 8453 
    network-id: 8453 
    currency: ETH

subgraphs:
  base-community: https://api.goldsky.com/api/public/project_clv14x04y9kzi01saerx7bxpg/subgraphs/ob4-base/0.1/gn
  
orderbooks:
  base-community:
    address: 0xA2f56F8F74B7d04d61f281BE6576b6155581dcBA
    network: base-community
    subgraph: base-community

deployers:
  base-community:
    address: 0x56394785a22b3BE25470a0e03eD9E0a939C47b9b
    network: base-community

scenarios:
    test :
        network: base-community
        deployer: base-community
        orderbook: base-community
        bindings:
          # Ask for now, registry in future.
          uniswap-words: 0xD6B34F97d4A8Cb38D0544dB241CB3f335866f490
          orderbook-subparser: 0x8D96ea3EF24D7123882c51CE4325b89bc0d63f9e

          # Uniswap V3 factory addresses and init code
          uniswap-v3-factory: 0x33128a8fC17869897dcE68Ed026d694621f6FDfD
          uniswap-v3-init-code: '[uniswap-v3-init-code]'

          # Token Bindings
          token: 0x99b2B1A2aDB02B38222ADcD057783D7e5D1FCC7D
          stable: 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913
          poolfee: "[uniswap-v3-fee-medium]"
          price-average-time: 600
          
        scenarios:
          backtest:
            runs: 1
            blocks:
              type: RangeWithInterval
              value:
                range: [18028702..18038702]
                interval: 100
                

charts:
  A. Test backtest:
    scenario: test.backtest
    plots:
      current-price:
        x:
          label: 'Block Number'
        y:
          label: 'Order Ratio'
        marks:
          - type: line
            options:
              stroke: blue
              x: 0.2
              y: 0.1
      average-price:
        x:
          label: 'Block Number'
        y:
          label: 'Order Ratio'
        marks:
          - type: line
            options:
              stroke: red
              x: 0.2
              y: 0.0
---
#token !the token address of the token.
#stable !the token address of the stable token.
#poolfee !the uniswap v3 pool fee for the pair.
#price-average-time !The length of the average price, measured in time by seconds.
#orderbook-subparser !The address for uniswap subparser.
#uniswap-words !The address for orderbook subparser.
#uniswap-v3-factory !Uniswap v3 factory.
#uniswap-v3-init-code !Uniswap v3 factory init code.

#calculate-io 
using-words-from orderbook-subparser uniswap-words

  price-average: uniswap-v3-twap-output-ratio(
    token stable 
    price-average-time 0
    uniswap-v3-factory uniswap-v3-init-code
    poolfee
  ),
  current-price: uniswap-v3-twap-output-ratio(
    token stable
    0 0
    uniswap-v3-factory uniswap-v3-init-code
    poolfee
  ),
  _: block-number(),
  _ _: 1 0; 

#handle-io
:;
  • Expected Curve :
    image
  • Actual Curve Generated :
    image
  • The average price for the generated curve is closer to the current price rather than being a smooth curve.
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

No branches or pull requests

2 participants