diff --git a/schema.graphql b/schema.graphql index eaec4aa..d45cec4 100644 --- a/schema.graphql +++ b/schema.graphql @@ -713,7 +713,7 @@ type Position @entity { tokenId: BigInt # tokenId indexes: [PositionLend!]! # list of PositionLends which constitute a position owner: Bytes! # address of the position owner - pool: Bytes! # address of the pool that the position is associated with + pool: Pool! # pool that the position is associated with token: Token! # pointer to LPToken entity tokenURI: String! # tokenURI of the positionNFT } diff --git a/src/mappings/position-manager.ts b/src/mappings/position-manager.ts index 298073f..d92c45c 100644 --- a/src/mappings/position-manager.ts +++ b/src/mappings/position-manager.ts @@ -1,4 +1,4 @@ -import { Address, BigInt, log } from "@graphprotocol/graph-ts" +import { BigInt, log } from "@graphprotocol/graph-ts" import { Approval as ApprovalEvent, ApprovalForAll as ApprovalForAllEvent, @@ -21,12 +21,9 @@ import { Transfer } from "../../generated/schema" import { getBucketId } from "../utils/pool/bucket" -import { lpbValueInQuote, saveOrRemoveLend } from "../utils/pool/lend" -import { ONE_BI, ZERO_BD } from "../utils/constants" +import { lpbValueInQuote } from "../utils/pool/lend" import { addressToBytes, bigIntArrayToIntArray, bigIntToBytes, wadToDecimal } from "../utils/convert" -import { getLendId, loadOrCreateLend } from "../utils/pool/lend" -import { deletePosition, getPoolForToken, getPositionInfo, getPositionLendId, loadOrCreateLPToken, loadOrCreatePosition, loadOrCreatePositionLend, saveOrRemovePositionLend, updatePositionLends } from "../utils/position" -import { getLenderInfo } from "../utils/pool/pool" +import { deletePosition, getPoolForToken, getPositionInfo, loadOrCreateLPToken, loadOrCreatePosition, loadOrCreatePositionLend, saveOrRemovePositionLend, updatePositionLends } from "../utils/position" import { getTokenURI } from "../utils/token-erc721" import { loadOrCreateAccount, updateAccountPositions } from "../utils/account" import { ONE_BI, ZERO_ADDRESS, ZERO_BD } from "../utils/constants"; @@ -100,9 +97,6 @@ export function handleMemorializePosition( memorialize.blockTimestamp = event.block.timestamp memorialize.transactionHash = event.transaction.hash - // update entities - const position = loadOrCreatePosition(memorialize.tokenId) - // get lend entities for each index with extant lpb const poolAddress = memorialize.pool const accountId = memorialize.lender @@ -125,12 +119,10 @@ export function handleMemorializePosition( // associate positionLend with Bucket and Position updatePositionLends(positionLend) - bucket.save() } // save entities to store memorialize.save() - position.save() } export function handleMint(event: MintEvent): void { diff --git a/src/utils/position.ts b/src/utils/position.ts index a18facc..fc46c08 100644 --- a/src/utils/position.ts +++ b/src/utils/position.ts @@ -73,16 +73,18 @@ export function updatePositionLends(positionLend: PositionLend): void { const bucket = Bucket.load(positionLend.bucket) if (bucket != null) { const existingBucketIndex = bucket.positionLends.indexOf(positionLend.id) - if (existingBucketIndex != -1) { + if (existingBucketIndex == -1) { bucket.positionLends = bucket.positionLends.concat([positionLend.id]) + bucket.save() } } // add positionLend to position array if necessary - const position = Position.load(bigIntToBytes(positionLend.tokenId))! + const position = loadOrCreatePosition(positionLend.tokenId) const existingPositionIndex = position.indexes.indexOf(positionLend.id) - if (existingPositionIndex != -1) { + if (existingPositionIndex == -1) { position.indexes = position.indexes.concat([positionLend.id]) + position.save() } }