{"_id":"@0xelod/uniswap-v3-backtest","name":"@0xelod/uniswap-v3-backtest","dist-tags":{"latest":"1.1.2"},"versions":{"1.1.2":{"name":"@0xelod/uniswap-v3-backtest","version":"1.1.2","description":"Fast and efficient method for testing Uniswap V3 LP Strategies","main":"index.js","type":"module","scripts":{"test":"node test.js"},"repository":{"type":"git","url":"git+https://github.com/DefiLab-xyz/uniswap-v3-backtest.git"},"keywords":["uniswap","uniswapV3","LP Strategy Backtester","backtester","defi","backtest"],"author":{"name":"staceb"},"license":"MIT","bugs":{"url":"https://github.com/DefiLab-xyz/uniswap-v3-backtest/issues"},"homepage":"https://github.com/DefiLab-xyz/uniswap-v3-backtest#readme","dependencies":{"node-fetch":"^3.2.4"},"access":"public","gitHead":"b52fbe6f129b27c5f1f1ce44f204314a71471699","_id":"@0xelod/uniswap-v3-backtest@1.1.2","_nodeVersion":"18.17.0","_npmVersion":"9.6.7","dist":{"integrity":"sha512-aBIXvtJ5yEmNntGpxakG1sQs5AbOIbeRYnJysRbDqryZv0KwrASFot319XaYfcGtAH0Q3nrHwuSCanhZy78YbA==","shasum":"71e647a2810c1e7a3230fe8ac91693cfb8c7a026","tarball":"https://registry.npmjs.org/@0xelod/uniswap-v3-backtest/-/uniswap-v3-backtest-1.1.2.tgz","fileCount":8,"unpackedSize":33158,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCitK2KllCEeFUjMybO1w9ZaFSE6uJe1upBioNNDG7a1gIgfVdwq9xw6usiHXf/FAxznWvAzIXp0q/8RXoWzQNKZfg="}]},"_npmUser":{"name":"0xelod","email":"elod.varga@taraxa.io"},"directories":{},"maintainers":[{"name":"0xelod","email":"elod.varga@taraxa.io"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/uniswap-v3-backtest_1.1.2_1710766423187_0.19014519788724726"},"_hasShrinkwrap":false}},"time":{"created":"2024-03-18T12:53:43.047Z","1.1.2":"2024-03-18T12:53:43.345Z","modified":"2024-03-18T12:53:44.375Z"},"maintainers":[{"name":"0xelod","email":"elod.varga@taraxa.io"}],"description":"Fast and efficient method for testing Uniswap V3 LP Strategies","homepage":"https://github.com/DefiLab-xyz/uniswap-v3-backtest#readme","keywords":["uniswap","uniswapV3","LP Strategy Backtester","backtester","defi","backtest"],"repository":{"type":"git","url":"git+https://github.com/DefiLab-xyz/uniswap-v3-backtest.git"},"author":{"name":"staceb"},"bugs":{"url":"https://github.com/DefiLab-xyz/uniswap-v3-backtest/issues"},"license":"MIT","readme":"# Uniswap V3 LP Strategy BackTester\n\nStrategy Backtester for providing liquidity to a Uniswap V3 Pool. Based on logic described in the following article:\n\n[Historical Performances of Uniswap V3 Pools](https://defi-lab.medium.com/historical-performances-of-uniswap-l3-pools-2de713f7c70f)\n\n![backtest-performance](https://user-images.githubusercontent.com/5744432/167617903-efd0829f-0b32-4c7f-b611-47398d8e435c.png)\n\n## Install\n\n```shell\nnpm install uniswap-v3-backtest\n```\n\n## Obtain pool IDs for Taraxa testnet\n\n- [Get the pool ids](https://indexer.lswap.app/subgraphs/name/lara-staking/uniswap-v3/graphql?query=query+poolIds%7B%0A++pools%28subgraphError%3A+deny%29%7B%0A++++id%0A++++token0+%7B%0A++++++id%0A++++%7D%0A++++token1+%7B%0A++++++id%0A++++%7D%0A++%7D%0A%7D)\n- [Get the pool data](https://indexer.lswap.app/subgraphs/name/lara-staking/uniswap-v3/graphql?query=%0A++++%23%0A++++%23+Welcome+to+The+GraphiQL%0A++++%23%0A++++%23+GraphiQL+is+an+in-browser+tool+for+writing%2C+validating%2C+and%0A++++%23+testing+GraphQL+queries.%0A++++%23%0A++++%23+Type+queries+into+this+side+of+the+screen%2C+and+you+will+see+intelligent%0A++++%23+typeaheads+aware+of+the+current+GraphQL+type+schema+and+live+syntax+and%0A++++%23+validation+errors+highlighted+within+the+text.%0A++++%23%0A++++%23+GraphQL+queries+typically+start+with+a+%22%7B%22+character.+Lines+that+start%0A++++%23+with+a+%23+are+ignored.%0A++++%23%0A++++%23+An+example+GraphQL+query+might+look+like%3A%0A++++%23%0A++++%23+++++%7B%0A++++%23+++++++field%28arg%3A+%22value%22%29+%7B%0A++++%23+++++++++subField%0A++++%23+++++++%7D%0A++++%23+++++%7D%0A++++%23%0A++++%23+Keyboard+shortcuts%3A%0A++++%23%0A++++%23++Prettify+Query%3A++Shift-Ctrl-P+%28or+press+the+prettify+button+above%29%0A++++%23%0A++++%23+++++Merge+Query%3A++Shift-Ctrl-M+%28or+press+the+merge+button+above%29%0A++++%23%0A++++%23+++++++Run+Query%3A++Ctrl-Enter+%28or+press+the+play+button+above%29%0A++++%23%0A++++%23+++Auto+Complete%3A++Ctrl-Space+%28or+just+start+typing%29%0A++++%23%0A%0A++++query+poolHourData+%7B%0A++++++poolHourDatas+%28orderBy%3AperiodStartUnix%2C+orderDirection%3Adesc%2C+first%3A1000%29+%7B%0A++++periodStartUnix%0A++++liquidity%0A++++high%0A++++low%0A++++pool+%7B%0A++++++id%0A++++++totalValueLockedUSD%0A++++++totalValueLockedToken1%0A++++++totalValueLockedToken0%0A++++++token0%0A++++++++%7Bdecimals%7D%0A++++++token1%0A++++++++%7Bdecimals%7D%0A++++%7D%0A++++close%0A++++feeGrowthGlobal0X128%0A++++feeGrowthGlobal1X128%0A++++%7D%0A++++%7D&operationName=poolHourData)\n\n## Usage\n\n```js\n// get results for last 25 days\nimport uniswapStrategyBacktest from \"uniswap-v3-backtest\";\nconst backtestResults = await uniswapStrategyBacktest(\n  \"0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640\",\n  1000,\n  2120.09,\n  2662.99,\n  { days: 25, period: \"daily\" }\n);\n\n// get results from start timestamp for lp from quote token\nawait uniswapStrategyBacktest(\n  \"0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640\",\n  1,\n  1 / 2662.99,\n  1 / 2120.09,\n  { startTimestamp: 1653364800, period: \"daily\", priceToken: 1 }\n);\n\n// get results from start timestamp to end timestamp for lp from quote token\nawait uniswapStrategyBacktest(\n  \"0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640\",\n  1,\n  1 / 2662.99,\n  1 / 2120.09,\n  {\n    startTimestamp: 1653364800,\n    endTimestamp: 1653374800,\n    period: \"daily\",\n    priceToken: 1,\n  }\n);\n\n// get results for n days before end timestamp for lp from quote token\nawait uniswapStrategyBacktest(\n  \"0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640\",\n  1,\n  1 / 2662.99,\n  1 / 2120.09,\n  { endTimestamp: 1653364800, days: 1, period: \"daily\", priceToken: 1 }\n);\n```\n\nExample Output:\n\n```\n\n// Hourly //\n\n{\n  periodStartUnix: 1652274000,\n  liquidity: '7675942584871332685',\n  high: '2266.726774269547858798641816695647',\n  low: '2145.393138561593202680715136665708',\n  pool: {\n    id: '0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640',\n    totalValueLockedUSD: '231193174.2181918276487229629805612',\n    totalValueLockedToken1: '71499.990198836160751569',\n    totalValueLockedToken0: '71417122.541685',\n    token0: { decimals: '6' },\n    token1: { decimals: '18' }\n  },\n  close: '2246.577649943233620476969923660446',\n  feeGrowthGlobal0X128: '1432478142734251891146870279471391',\n  feeGrowthGlobal1X128: '491787243029421936881695073823469456119843',\n  day: 11,\n  month: 4,\n  year: 2022,\n  fg0: 0,\n  fg1: 0,\n  activeliquidity: 100,\n  feeToken0: 0,\n  feeToken1: 0,\n  tokens: [ 259.4720394308191, 0.3296249121804859 ],\n  fgV: 0,\n  feeV: 0,\n  feeUnb: 0,\n  amountV: 999.9999999999999,\n  amountTR: 1000,\n  feeUSD: 0,\n  baseClose: '2246.577649943233620476969923660446'\n}\n\n// Daily //\n{\n  date: '5/11/2022',\n  day: 11,\n  month: 4,\n  year: 2022,\n  feeToken0: -3.4440601554207775,\n  feeToken1: -0.0015405996636897285,\n  feeV: -7.061140100789986,\n  feeUnb: -0.1933135552371638,\n  fgV: -3.677055720111889e-14,\n  feeUSD: -5.640380083495151,\n  activeliquidity: 100,\n  amountV: 999.9999999999998,\n  amountTR: 1000,\n  amountVLast: 1032.5671065225727,\n  percFee: -0.7061140100789988,\n  close: '2241.121068655049392145921171725936',\n  baseClose: '2241.121068655049392145921171725936',\n  count: 14\n}\n```\n\n## **uniswapStrategyBacktest() input**\n\nuniswapStrategyBacktest() should be called with the following arguments:\n\n```\nuniswapStrategyBacktest(\n  poolID,\n  investmentAmount,\n  minRange,\n  maxRange,\n  options\n)\n```\n\n**poolID** = the ID of the pool you'd like to run the backtest for. Example for [ETH / USD 0.05%](https://info.uniswap.org/#/pools/0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640) would be \"0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640\"\n\n**investmentAmount** = the initial amount invested in the LP strategy. This value is presumed to be denominated in the base token of the pair (Token0) but can be overridden to use the quote token with the options argument.\n\n**minRange** = the lower bound of the LP Strategy. As with investmentAmount, presumed to be in base but can be overridden to use quote.  \n**maxRange** = the upper bound of the LP Strategy. As with investmentAmount, presumed to be in base but can be overridden to use quote.\n\n**options** = Optional values that override default values. Formed as a JSON key value pair `{days: 30, protocol: 0, priceToken: 0, period: \"hourly\"}`  \n **days** = number of days to run the backtest from todays date. Defaults to 30, Currently maxed to 30.  \n **startTimestamp** = timestamp in seconds for LP start. Optional.  \n **endTimestamp** = timestamp in seconds for LP end. Optional. If used with _days_ provides results for `n` days before timestamp  \n **priceToken** = 0 = values in baseToken, 1 = values in quoteToken (Token0, Token1)\n**period** = Calculate fees \"daily\" or \"hourly\", defaults to \"hourly\"  \n **protocol** - Which chain, sidechain or L2 to use:  \n 0 = Ethereum (default)  \n 1 = Optimism  \n 2 = Arbitrum  \n 3 = Polygon\n\n## **uniswapStrategyBacktest() output**\n\n**amountV** = the total value of the LP position for the specified period.  \n**feeV** = the fees generated for the specified period.  \n**activeliquidity** = the % of the strategies liquidity that was active within the specified period.  \n**feeUSD** = the total fees in USD\n","readmeFilename":"README.md"}