Catalog npm
Back to packageRELEASE DETAILS

1.1.2

npm

@0xelod/uniswap-v3-backtest

Fast and efficient method for testing Uniswap V3 LP Strategies

backtestbacktesterdefilp strategy backtesteruniswapuniswapv3
Published18 Mar 2024
Direct dependencies1
Transitive dependenciesNot calculated

README

Current package documentation

Uniswap V3 LP Strategy BackTester

Strategy Backtester for providing liquidity to a Uniswap V3 Pool. Based on logic described in the following article:

Historical Performances of Uniswap V3 Pools

backtest-performance

Install

npm install uniswap-v3-backtest

Obtain pool IDs for Taraxa testnet

Usage

// get results for last 25 days
import uniswapStrategyBacktest from "uniswap-v3-backtest";
const backtestResults = await uniswapStrategyBacktest(
  "0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640",
  1000,
  2120.09,
  2662.99,
  { days: 25, period: "daily" }
);

// get results from start timestamp for lp from quote token
await uniswapStrategyBacktest(
  "0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640",
  1,
  1 / 2662.99,
  1 / 2120.09,
  { startTimestamp: 1653364800, period: "daily", priceToken: 1 }
);

// get results from start timestamp to end timestamp for lp from quote token
await uniswapStrategyBacktest(
  "0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640",
  1,
  1 / 2662.99,
  1 / 2120.09,
  {
    startTimestamp: 1653364800,
    endTimestamp: 1653374800,
    period: "daily",
    priceToken: 1,
  }
);

// get results for n days before end timestamp for lp from quote token
await uniswapStrategyBacktest(
  "0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640",
  1,
  1 / 2662.99,
  1 / 2120.09,
  { endTimestamp: 1653364800, days: 1, period: "daily", priceToken: 1 }
);

Example Output:


// Hourly //

{
  periodStartUnix: 1652274000,
  liquidity: '7675942584871332685',
  high: '2266.726774269547858798641816695647',
  low: '2145.393138561593202680715136665708',
  pool: {
    id: '0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640',
    totalValueLockedUSD: '231193174.2181918276487229629805612',
    totalValueLockedToken1: '71499.990198836160751569',
    totalValueLockedToken0: '71417122.541685',
    token0: { decimals: '6' },
    token1: { decimals: '18' }
  },
  close: '2246.577649943233620476969923660446',
  feeGrowthGlobal0X128: '1432478142734251891146870279471391',
  feeGrowthGlobal1X128: '491787243029421936881695073823469456119843',
  day: 11,
  month: 4,
  year: 2022,
  fg0: 0,
  fg1: 0,
  activeliquidity: 100,
  feeToken0: 0,
  feeToken1: 0,
  tokens: [ 259.4720394308191, 0.3296249121804859 ],
  fgV: 0,
  feeV: 0,
  feeUnb: 0,
  amountV: 999.9999999999999,
  amountTR: 1000,
  feeUSD: 0,
  baseClose: '2246.577649943233620476969923660446'
}

// Daily //
{
  date: '5/11/2022',
  day: 11,
  month: 4,
  year: 2022,
  feeToken0: -3.4440601554207775,
  feeToken1: -0.0015405996636897285,
  feeV: -7.061140100789986,
  feeUnb: -0.1933135552371638,
  fgV: -3.677055720111889e-14,
  feeUSD: -5.640380083495151,
  activeliquidity: 100,
  amountV: 999.9999999999998,
  amountTR: 1000,
  amountVLast: 1032.5671065225727,
  percFee: -0.7061140100789988,
  close: '2241.121068655049392145921171725936',
  baseClose: '2241.121068655049392145921171725936',
  count: 14
}

uniswapStrategyBacktest() input

uniswapStrategyBacktest() should be called with the following arguments:

uniswapStrategyBacktest(
  poolID,
  investmentAmount,
  minRange,
  maxRange,
  options
)

poolID = the ID of the pool you'd like to run the backtest for. Example for ETH / USD 0.05% would be "0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640"

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.

minRange = the lower bound of the LP Strategy. As with investmentAmount, presumed to be in base but can be overridden to use quote.
maxRange = the upper bound of the LP Strategy. As with investmentAmount, presumed to be in base but can be overridden to use quote.

options = Optional values that override default values. Formed as a JSON key value pair {days: 30, protocol: 0, priceToken: 0, period: "hourly"}
days = number of days to run the backtest from todays date. Defaults to 30, Currently maxed to 30.
startTimestamp = timestamp in seconds for LP start. Optional.
endTimestamp = timestamp in seconds for LP end. Optional. If used with days provides results for n days before timestamp
priceToken = 0 = values in baseToken, 1 = values in quoteToken (Token0, Token1) period = Calculate fees "daily" or "hourly", defaults to "hourly"
protocol - Which chain, sidechain or L2 to use:
0 = Ethereum (default)
1 = Optimism
2 = Arbitrum
3 = Polygon

uniswapStrategyBacktest() output

amountV = the total value of the LP position for the specified period.
feeV = the fees generated for the specified period.
activeliquidity = the % of the strategies liquidity that was active within the specified period.
feeUSD = the total fees in USD

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Declared dependencies 1

Native requirements
1 direct targetsNot calculated transitive count
Package / targetRequirementRelationship
node-fetch
Environment
{
  "local_name": "node-fetch",
  "alias": false,
  "peer_metadata": null
}
^3.2.4runtime

Distribution files

1 collected
Distribution 1

Source distribution

Source file
Checksums from source
{
  "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="
    }
  ]
}

Repository

PENDING
defilab-xyz/uniswap-v3-backtest

Shared repository data · GitHub

License detected in repository
Not collected

Metadata history

Meaningful changes
Current collected state Current

Observed since 20 Oct, 23:07 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package_version:e70b1f5d7f2a8f7cd9a7e0a34edfe2813ebc84f4f00fbd780c128688bee54aaa

Other collected versions

View all collected versions →