Skip to content

Commit

Permalink
fix handleTransfer account position associations
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike committed Aug 23, 2023
1 parent 990ff2b commit d3e4557
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/mappings/position-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,13 +311,16 @@ export function handleTransfer(event: TransferEvent): void {
position.tokenURI = getTokenURI(event.address, transfer.tokenId)

// remove position from old account
const account = loadOrCreateAccount(transfer.from)
const index = account.positions.indexOf(bigIntToBytes(transfer.tokenId))
if (index != -1) account.positions.splice(index, 1)
updateAccountPositions(account, position)
const oldOwnerAccount = loadOrCreateAccount(transfer.from)
const index = oldOwnerAccount.positions.indexOf(bigIntToBytes(transfer.tokenId))
if (index != -1) oldOwnerAccount.positions.splice(index, 1)
// add position to new account
const newOwnerAccount = loadOrCreateAccount(transfer.to)
updateAccountPositions(newOwnerAccount, position)

// save entities to store
account.save()
oldOwnerAccount.save()
newOwnerAccount.save()
token.save();
position.save()
transfer.save()
Expand Down
3 changes: 3 additions & 0 deletions tests/position-manager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ describe("Describe entity assertions", () => {

// check position attributes
assertPosition(lender, pool, tokenId, tokenContractAddress)
assert.entityCount("Account", 1)

/****************************/
/*** Memorialize Position ***/
Expand All @@ -326,6 +327,7 @@ describe("Describe entity assertions", () => {
assertPosition(lender, pool, tokenId, tokenContractAddress)
// TODO: check index attributes -> assertPositionLend

assert.entityCount("Account", 1)
assert.entityCount("Mint", 1)
assert.entityCount("Lend", 2)
assert.entityCount("MemorializePosition", 1)
Expand Down Expand Up @@ -356,6 +358,7 @@ describe("Describe entity assertions", () => {
assertPositionLend(getPositionLendId(tokenId, fromIndex).toHexString(), getBucketId(pool, fromIndex.toU32()).toHexString(), expectedDepositTime, lpb.minus(lpRedeemedFrom))
assertPositionLend(getPositionLendId(tokenId, toIndex).toHexString(), getBucketId(pool, toIndex.toU32()).toHexString(), expectedDepositTime, lpRedeemedTo)

assert.entityCount("Account", 1)
assert.entityCount("Mint", 1)
assert.entityCount("MemorializePosition", 1)
assert.entityCount("Position", 1)
Expand Down

0 comments on commit d3e4557

Please sign in to comment.