Skip to content

Commit

Permalink
Merge branch 'main' into fix/stats-pnl
Browse files Browse the repository at this point in the history
  • Loading branch information
avclarke committed Feb 21, 2024
2 parents a1caa6d + cd894ef commit dfc045d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
11 changes: 7 additions & 4 deletions src/perps-v3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ export function handlePositionLiquidated(event: PositionLiquidatedEvent): void {
liquidation.timestamp = event.block.timestamp;
liquidation.save();

let statEntity = PerpsV3Stat.load(account.owner.toHex());
let statId = event.params.accountId.toString() + '-' + account.owner.toHexString();
let statEntity = PerpsV3Stat.load(statId);

if (openPosition === null) {
log.warning('Position entity not found for positionId {}', [positionId]);
Expand Down Expand Up @@ -168,11 +169,13 @@ export function handleOrderSettled(event: OrderSettledEvent): void {
return;
}

let statEntity = PerpsV3Stat.load(account.owner.toHex());
let statId = event.params.accountId.toString() + '-' + account.owner.toHexString();
let statEntity = PerpsV3Stat.load(statId);

if (statEntity == null) {
statEntity = new PerpsV3Stat(account.owner.toHex());
statEntity.account = account.owner;
statEntity = new PerpsV3Stat(statId);
statEntity.accountId = event.params.accountId;
statEntity.accountOwner = account.owner;
statEntity.feesPaid = ZERO;
statEntity.pnl = ZERO;
statEntity.pnlWithFeesPaid = ZERO;
Expand Down
3 changes: 2 additions & 1 deletion subgraphs/perps-v3.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ type CollateralChange @entity {

type PerpsV3Stat @entity {
id: ID!
account: Bytes!
accountId: BigInt!
accountOwner: Bytes!
feesPaid: BigInt!
pnl: BigInt!
pnlWithFeesPaid: BigInt!
Expand Down

0 comments on commit dfc045d

Please sign in to comment.