Skip to content

Commit

Permalink
fix: Add support for MCv3 owner
Browse files Browse the repository at this point in the history
  • Loading branch information
0xjojoex committed Nov 30, 2023
1 parent 0144cd6 commit c98faf0
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
Transfer,
} from "../generated/NonfungiblePositionManager/NonfungiblePositionManager";
import { loadTransaction, updateUserPosition } from "../utils/schema";
import { ADDRESS_ZERO } from "../utils/constants";
import { ADDRESS_ZERO, MASTERCHEF_ADDRESS } from "../utils/constants";
import { UserPosition } from "../generated/schema";

export function handleIncreaseLiquidity(event: IncreaseLiquidity): void {
Expand All @@ -30,6 +30,9 @@ export function handleTransfer(event: Transfer): void {
} else {
let userPosition = UserPosition.load(event.params.tokenId.toString());
userPosition.owner = event.params.to;
if (!event.params.to.equals(Address.fromString(MASTERCHEF_ADDRESS))) {
userPosition.originOwner = event.params.to;
}
userPosition.save();
}
transaction.save();
Expand Down
3 changes: 1 addition & 2 deletions subgraphs/user-position-v3/template/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
"author": "PancakeSwap",
"license": "GPL-3.0-or-later",
"scripts": {
"template": "mustache ../../../config/bsc.js subgraph.template.yaml > subgraph.yaml",
"auth": "graph auth --product hosted-service f4b727b41dd3465f461ee000115b1102",
"template": "mustache ../../../config/$NETWORK.js subgraph.template.yaml > subgraph.yaml && mustache ../../../config/$NETWORK.js utils/constants.template.ts > utils/constants.ts",
"codegen": "graph codegen subgraph.yaml",
"build": "graph build subgraph.yaml",
"deploy:goerli": "graph deploy --product hosted-service --node https://api.thegraph.com/deploy/ --ipfs https://api.thegraph.com/ipfs/ pancakeswap/user-position-v3-goerli subgraph.yaml",
Expand Down
3 changes: 3 additions & 0 deletions subgraphs/user-position-v3/template/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,10 @@ type Burn @entity {
type UserPosition @entity {
# tokenId
id: ID!
# current owner of position
owner: Bytes!
# the owner of the position consider after transfer to MasterChef
originOwner: Bytes!
# pool position is within
pool: Pool

Expand Down
10 changes: 5 additions & 5 deletions subgraphs/user-position-v3/template/subgraph.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ features:
dataSources:
- kind: ethereum/contract
name: Factory
network: bsc
network: mainnet
source:
address: "0x0bfbcf9fa4f9c56b0f40a671ad40e0805a091865"
abi: Factory
startBlock: 26956207
startBlock: 16950686
mapping:
kind: ethereum/events
apiVersion: 0.0.4
Expand All @@ -37,11 +37,11 @@ dataSources:
handler: handlePoolCreated
- kind: ethereum/contract
name: NonfungiblePositionManager
network: bsc
network: mainnet
source:
address: "0x46a15b0b27311cedf172ab29e4f4766fbe7f4364"
abi: NonfungiblePositionManager
startBlock: 26931961
startBlock: 16944786
mapping:
kind: ethereum/events
apiVersion: 0.0.4
Expand Down Expand Up @@ -69,7 +69,7 @@ dataSources:
templates:
- kind: ethereum/contract
name: Pool
network: bsc
network: mainnet
source:
abi: Pool
mapping:
Expand Down
11 changes: 11 additions & 0 deletions subgraphs/user-position-v3/template/utils/constants.template.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* 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");

export const MASTERCHEF_ADDRESS = "{{ masterChefV3.masterChefAddress }}";
2 changes: 2 additions & 0 deletions subgraphs/user-position-v3/template/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ 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");

export const MASTERCHEF_ADDRESS = "0x556b9306565093c855aea9ae92a594704c2cd59e";
1 change: 1 addition & 0 deletions subgraphs/user-position-v3/template/utils/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export function updateUserPosition(event: ethereum.Event, tx: Transaction): void
userPosition.tickLower = tx.tickLower as BigInt;
userPosition.tickUpper = tx.tickUpper as BigInt;
userPosition.owner = tx.positionOwner as Bytes;
userPosition.originOwner = tx.positionOwner as Bytes;
if (tx.increaseLiquidityAmount !== null) {
userPosition.liquidity = userPosition.liquidity.plus(tx.increaseLiquidityAmount as BigInt);
}
Expand Down

0 comments on commit c98faf0

Please sign in to comment.