Skip to content

Commit

Permalink
Merge pull request #101 from Uniswap/match-with-deployed
Browse files Browse the repository at this point in the history
fix: update main with current version at ianlapham/uniswap-v3-subgraph
  • Loading branch information
ianlapham authored Mar 21, 2022
2 parents 1393818 + c63cb39 commit bf03f94
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 41 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"build": "graph build",
"create-local": "graph create ianlapham/uniswap-v3 --node http://127.0.0.1:8020",
"deploy-local": "graph deploy ianlapham/uniswap-v3 --debug --ipfs http://localhost:5001 --node http://127.0.0.1:8020",
"deploy": "graph deploy uniswap/uniswap-v3 --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/ --debug",
"deploy": "graph deploy ianlapham/uniswap-v3-subgraph --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/ --debug",
"deploy-dev": "graph deploy sommelier/uniswap-v3 --ipfs http://35.197.14.14:5000/ --node http://35.197.14.14:8020/ --debug",
"deploy-staging": "graph deploy $THE_GRAPH_GITHUB_USER/$THE_GRAPH_SUBGRAPH_NAME /Uniswap --ipfs https://api.staging.thegraph.com/ipfs/ --node https://api.staging.thegraph.com/deploy/",
"watch-local": "graph deploy ianlapham/uniswap-v3 --watch --debug --node http://127.0.0.1:8020/ --ipfs http://localhost:5001"
Expand Down
6 changes: 0 additions & 6 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -219,12 +219,6 @@ type Position @entity {
collectedFeesToken0: BigDecimal!
# all time collected fees in token1
collectedFeesToken1: BigDecimal!
# Total amount deposited in terms of USD
amountDepositedUSD: BigDecimal!
# Total amount withdrawn in terms of USD
amountWithdrawnUSD: BigDecimal!
# Total amount collected in terms of USD
amountCollectedUSD: BigDecimal!
# tx in which the position was initialized
transaction: Transaction!
# vars needed for fee computation
Expand Down
43 changes: 12 additions & 31 deletions src/mappings/position-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@ function getPosition(event: ethereum.Event, tokenId: BigInt): Position | null {
position.transaction = loadTransaction(event).id
position.feeGrowthInside0LastX128 = positionResult.value8
position.feeGrowthInside1LastX128 = positionResult.value9

position.amountDepositedUSD = ZERO_BD
position.amountWithdrawnUSD = ZERO_BD
position.amountCollectedUSD = ZERO_BD
}
}

Expand Down Expand Up @@ -84,6 +80,11 @@ function savePositionSnapshot(position: Position, event: ethereum.Event): void {
}

export function handleIncreaseLiquidity(event: IncreaseLiquidity): void {
// temp fix
if (event.block.number.equals(BigInt.fromI32(14317993))) {
return
}

let position = getPosition(event, event.params.tokenId)

// position was not able to be fetched
Expand All @@ -95,7 +96,6 @@ export function handleIncreaseLiquidity(event: IncreaseLiquidity): void {
if (Address.fromString(position.pool).equals(Address.fromHexString('0x8fe8d9bb8eeba3ed688069c3d6b556c9ca258248'))) {
return
}
let bundle = Bundle.load('1')

let token0 = Token.load(position.token0)
let token1 = Token.load(position.token1)
Expand All @@ -107,11 +107,6 @@ export function handleIncreaseLiquidity(event: IncreaseLiquidity): void {
position.depositedToken0 = position.depositedToken0.plus(amount0)
position.depositedToken1 = position.depositedToken1.plus(amount1)

let newDepositUSD = amount0
.times(token0.derivedETH.times(bundle.ethPriceUSD))
.plus(amount1.times(token1.derivedETH.times(bundle.ethPriceUSD)))
position.amountDepositedUSD = position.amountDepositedUSD.plus(newDepositUSD)

updateFeeVars(position!, event, event.params.tokenId)

position.save()
Expand All @@ -120,6 +115,11 @@ export function handleIncreaseLiquidity(event: IncreaseLiquidity): void {
}

export function handleDecreaseLiquidity(event: DecreaseLiquidity): void {
// temp fix
if (event.block.number == BigInt.fromI32(14317993)) {
return
}

let position = getPosition(event, event.params.tokenId)

// position was not able to be fetched
Expand All @@ -132,7 +132,6 @@ export function handleDecreaseLiquidity(event: DecreaseLiquidity): void {
return
}

let bundle = Bundle.load('1')
let token0 = Token.load(position.token0)
let token1 = Token.load(position.token1)
let amount0 = convertTokenToDecimal(event.params.amount0, token0.decimals)
Expand All @@ -142,11 +141,6 @@ export function handleDecreaseLiquidity(event: DecreaseLiquidity): void {
position.withdrawnToken0 = position.withdrawnToken0.plus(amount0)
position.withdrawnToken1 = position.withdrawnToken1.plus(amount1)

let newWithdrawUSD = amount0
.times(token0.derivedETH.times(bundle.ethPriceUSD))
.plus(amount1.times(token1.derivedETH.times(bundle.ethPriceUSD)))
position.amountWithdrawnUSD = position.amountWithdrawnUSD.plus(newWithdrawUSD)

position = updateFeeVars(position!, event, event.params.tokenId)
position.save()
savePositionSnapshot(position!, event)
Expand All @@ -162,23 +156,10 @@ export function handleCollect(event: Collect): void {
return
}


let bundle = Bundle.load('1')
let token0 = Token.load(position.token0)
let token1 = Token.load(position.token1)
let amount0 = convertTokenToDecimal(event.params.amount0, token0.decimals)
let amount1 = convertTokenToDecimal(event.params.amount1, token1.decimals)
position.collectedToken0 = position.collectedToken0.plus(amount0)
position.collectedToken1 = position.collectedToken1.plus(amount1)

position.collectedFeesToken0 = position.collectedToken0.minus(position.withdrawnToken0)
position.collectedFeesToken1 = position.collectedToken1.minus(position.withdrawnToken1)

let newCollectUSD = amount0
.times(token0.derivedETH.times(bundle.ethPriceUSD))
.plus(amount1.times(token1.derivedETH.times(bundle.ethPriceUSD)))
position.amountCollectedUSD = position.amountCollectedUSD.plus(newCollectUSD)

position.collectedFeesToken0 = position.collectedFeesToken0.plus(amount0)
position.collectedFeesToken1 = position.collectedFeesToken1.plus(amount0)

position = updateFeeVars(position!, event, event.params.tokenId)
position.save()
Expand Down
2 changes: 1 addition & 1 deletion src/utils/pricing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ let STABLE_COINS: string[] = [
'0x4dd28568d05f09b02220b09c2cb307bfd837cb95'
]

let MINIMUM_ETH_LOCKED = BigDecimal.fromString('52')
let MINIMUM_ETH_LOCKED = BigDecimal.fromString('60')

let Q192 = 2 ** 192
export function sqrtPriceX96ToTokenPrices(sqrtPriceX96: BigInt, token0: Token, token1: Token): BigDecimal[] {
Expand Down
6 changes: 4 additions & 2 deletions subgraph.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ repository: https://github.com/Uniswap/uniswap-v3-subgraph
schema:
file: ./schema.graphql
graft:
base: QmZeCuoZeadgHkGwLwMeguyqUKz1WPWQYKcKyMCeQqGhsF
block: 12673736
base: QmPrb5mvZj3ycUugZgwLWCvK93jfXfhvfjRXrFk4tRmyCX
block: 14292820
features:
- nonFatalErrors
dataSources:
- kind: ethereum/contract
name: Factory
Expand Down

0 comments on commit bf03f94

Please sign in to comment.