-
Notifications
You must be signed in to change notification settings - Fork 587
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Add user position calculation
- Loading branch information
Showing
11 changed files
with
207 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 16 additions & 1 deletion
17
subgraphs/user-position-v3/template/mappings/position-manager.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,34 @@ | ||
/* eslint-disable prefer-const */ | ||
import { Address } from "@graphprotocol/graph-ts"; | ||
import { | ||
DecreaseLiquidity, | ||
IncreaseLiquidity, | ||
Transfer, | ||
} from "../generated/NonfungiblePositionManager/NonfungiblePositionManager"; | ||
import { loadTransaction } from "../utils"; | ||
import { loadTransaction } from "../utils/schema"; | ||
import { ADDRESS_ZERO } from "../utils/constants"; | ||
import { UserPosition } from "../generated/schema"; | ||
|
||
export function handleIncreaseLiquidity(event: IncreaseLiquidity): void { | ||
let transaction = loadTransaction(event); | ||
transaction.tokenId = event.params.tokenId; | ||
transaction.save(); | ||
} | ||
|
||
export function handleDecreaseLiquidity(event: DecreaseLiquidity): void { | ||
let transaction = loadTransaction(event); | ||
transaction.tokenId = event.params.tokenId; | ||
transaction.save(); | ||
} | ||
|
||
export function handleTransfer(event: Transfer): void { | ||
let transaction = loadTransaction(event); | ||
if (event.params.from.equals(Address.fromString(ADDRESS_ZERO))) { | ||
transaction.positionOwner = event.params.to; | ||
} else { | ||
let userPosition = UserPosition.load(event.params.tokenId.toString()); | ||
userPosition.owner = event.params.to; | ||
userPosition.save(); | ||
} | ||
transaction.save(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
specVersion: 0.0.2 | ||
description: PancakeSwap is a multi-chain decentralized exchange and automated market maker protocol. | ||
repository: https://github.com/pancakeswap/pancake-subgraph | ||
schema: | ||
file: ./schema.graphql | ||
features: | ||
- nonFatalErrors | ||
dataSources: | ||
- kind: ethereum/contract | ||
name: Factory | ||
network: bsc | ||
source: | ||
address: "0x0bfbcf9fa4f9c56b0f40a671ad40e0805a091865" | ||
abi: Factory | ||
startBlock: 26956207 | ||
mapping: | ||
kind: ethereum/events | ||
apiVersion: 0.0.4 | ||
language: wasm/assemblyscript | ||
file: ./mappings/factory.ts | ||
entities: | ||
- Pool | ||
- Token | ||
abis: | ||
- name: Factory | ||
file: ./abis/factory.json | ||
- name: ERC20 | ||
file: ./abis/ERC20.json | ||
- name: ERC20SymbolBytes | ||
file: ./abis/ERC20SymbolBytes.json | ||
- name: ERC20NameBytes | ||
file: ./abis/ERC20NameBytes.json | ||
- name: Pool | ||
file: ./abis/pool.json | ||
eventHandlers: | ||
- event: PoolCreated(indexed address,indexed address,indexed uint24,int24,address) | ||
handler: handlePoolCreated | ||
- kind: ethereum/contract | ||
name: NonfungiblePositionManager | ||
network: bsc | ||
source: | ||
address: "0x46a15b0b27311cedf172ab29e4f4766fbe7f4364" | ||
abi: NonfungiblePositionManager | ||
startBlock: 26931961 | ||
mapping: | ||
kind: ethereum/events | ||
apiVersion: 0.0.4 | ||
language: wasm/assemblyscript | ||
file: ./mappings/position-manager.ts | ||
entities: | ||
- Pool | ||
- Token | ||
abis: | ||
- name: NonfungiblePositionManager | ||
file: ./abis/NonfungiblePositionManager.json | ||
- name: Pool | ||
file: ./abis/pool.json | ||
- name: Factory | ||
file: ./abis/factory.json | ||
- name: ERC20 | ||
file: ./abis/ERC20.json | ||
eventHandlers: | ||
- event: IncreaseLiquidity(indexed uint256,uint128,uint256,uint256) | ||
handler: handleIncreaseLiquidity | ||
- event: DecreaseLiquidity(indexed uint256,uint128,uint256,uint256) | ||
handler: handleDecreaseLiquidity | ||
- event: Transfer(indexed address,indexed address,indexed uint256) | ||
handler: handleTransfer | ||
templates: | ||
- kind: ethereum/contract | ||
name: Pool | ||
network: bsc | ||
source: | ||
abi: Pool | ||
mapping: | ||
kind: ethereum/events | ||
apiVersion: 0.0.4 | ||
language: wasm/assemblyscript | ||
file: ./mappings/pool.ts | ||
entities: | ||
- Pool | ||
- Token | ||
abis: | ||
- name: Pool | ||
file: ./abis/pool.json | ||
- name: Factory | ||
file: ./abis/factory.json | ||
- name: ERC20 | ||
file: ./abis/ERC20.json | ||
eventHandlers: | ||
- event: Mint(address,indexed address,indexed int24,indexed int24,uint128,uint256,uint256) | ||
handler: handleMint | ||
- event: Burn(indexed address,indexed int24,indexed int24,uint128,uint256,uint256) | ||
handler: handleBurn |
17 changes: 0 additions & 17 deletions
17
subgraphs/user-position-v3/template/utils/constants.template.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/* eslint-disable prefer-const */ | ||
import { BigInt, BigDecimal } from "@graphprotocol/graph-ts"; | ||
|
||
export const ADDRESS_ZERO = "0x0000000000000000000000000000000000000000"; | ||
|
||
export let ZERO_BI = BigInt.fromI32(0); | ||
export let ONE_BI = BigInt.fromI32(1); | ||
export let ZERO_BD = BigDecimal.fromString("0"); | ||
export let ONE_BD = BigDecimal.fromString("1"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.