Skip to content

Commit

Permalink
cleanup schema and expand position tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike committed Aug 23, 2023
1 parent 64ee17f commit 0333536
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
4 changes: 1 addition & 3 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -706,15 +706,13 @@ type MergeOrRemoveCollateralNFT @entity(immutable: true) {
# POSITION MANAGER ENTITIES #
# # # # # # # # # # # # # # #

# TODO: associate with LPToken
type Position @entity {
id: Bytes! # byte encoded tokenId
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
token: Token! # pointer to positionNFT
tokenAddress: String! # address of the Position Manager Contract, encoded as hex string
token: Token! # pointer to LPToken entity
tokenURI: String! # tokenURI of the positionNFT
}

Expand Down
3 changes: 1 addition & 2 deletions src/utils/position.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ export function loadOrCreatePosition(tokenId: BigInt): Position {
position.indexes = []
position.owner = Bytes.empty()
position.pool = Bytes.empty()
position.token = Bytes.empty()
position.tokenAddress = positionManagerAddress.toHexString()
position.token = addressToBytes(positionManagerAddress)
position.tokenURI = getTokenURI(positionManagerAddress, tokenId)
}
return position
Expand Down
21 changes: 20 additions & 1 deletion tests/position-manager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ describe("Describe entity assertions", () => {
// check position attributes
assertPosition(lender, pool, tokenId, tokenContractAddress)

// check entity count after mint and before burn
assert.entityCount("Burn", 0)
assert.entityCount("Mint", 1)
assert.entityCount("Position", 1)
Expand All @@ -121,9 +122,11 @@ describe("Describe entity assertions", () => {
`${tokenId}`
)

// check entity count after burn
assert.entityCount("Burn", 1)
assert.entityCount("Mint", 1)
// assert.entityCount("Position", 1)
assert.entityCount("Position", 0)
assert.entityCount("Token", 3)
})

test("Mint", () => {
Expand All @@ -141,8 +144,24 @@ describe("Describe entity assertions", () => {
// check position attributes
assertPosition(lender, pool, tokenId, tokenContractAddress)

// check mint attributes
assert.fieldEquals(
"Mint",
`0xa16081f360e3847006db660bae1c6d1b2e17ec2a01000000`,
"lender",
`${lender.toHexString()}`
)
assert.fieldEquals(
"Mint",
`0xa16081f360e3847006db660bae1c6d1b2e17ec2a01000000`,
"tokenId",
`${tokenId}`
)

// check entity count
assert.entityCount("Mint", 1)
assert.entityCount("Position", 1)
assert.entityCount("Token", 3)
})

test("Memorialize", () => {
Expand Down

0 comments on commit 0333536

Please sign in to comment.