Skip to content

Commit

Permalink
Merge pull request #79 from ajna-finance/burn-position-fix
Browse files Browse the repository at this point in the history
fix: don't update position in handleTransfer for burn address
  • Loading branch information
imbaniac authored Nov 8, 2023
2 parents d73b0ec + 01b1725 commit 43ca0dc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.DS_Store
build/
generated/
data*/
Expand Down
39 changes: 23 additions & 16 deletions src/mappings/position-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { deletePosition, getPoolForToken, getPositionInfo, getPositionLendId, lo
import { getLenderInfo } from "../utils/pool/pool"
import { getTokenURI } from "../utils/token-erc721"
import { loadOrCreateAccount, updateAccountPositions } from "../utils/account"
import { ONE_BI, ZERO_ADDRESS, ZERO_BD } from "../utils/constants";

export function handleApproval(event: ApprovalEvent): void {
const approval = new Approval(
Expand Down Expand Up @@ -281,25 +282,31 @@ export function handleTransfer(event: TransferEvent): void {
const token = loadOrCreateLPToken(event.address);
transfer.token = token.id;
token.txCount = token.txCount.plus(ONE_BI);
const position = loadOrCreatePosition(transfer.tokenId)
position.owner = event.params.to
position.tokenURI = getTokenURI(event.address, transfer.tokenId)

// remove position from old account
const oldOwnerAccount = loadOrCreateAccount(transfer.from)
const index = oldOwnerAccount.positions.indexOf(bigIntToBytes(transfer.tokenId))
const accountPositions = oldOwnerAccount.positions
if (index != -1) accountPositions.splice(index, 1)
oldOwnerAccount.positions = accountPositions
if (event.params.to != ZERO_ADDRESS) {
const position = loadOrCreatePosition(transfer.tokenId);
position.owner = event.params.to;
position.tokenURI = getTokenURI(event.address, transfer.tokenId);

// add position to new account
const newOwnerAccount = loadOrCreateAccount(transfer.to)
updateAccountPositions(newOwnerAccount, position)
// add position to new account
const newOwnerAccount = loadOrCreateAccount(transfer.to);
updateAccountPositions(newOwnerAccount, position);

position.save();
newOwnerAccount.save();
}

// remove position from old account
const oldOwnerAccount = loadOrCreateAccount(transfer.from);
const index = oldOwnerAccount.positions.indexOf(
bigIntToBytes(transfer.tokenId)
);
const accountPositions = oldOwnerAccount.positions;
if (index != -1) accountPositions.splice(index, 1);
oldOwnerAccount.positions = accountPositions;

// save entities to store
oldOwnerAccount.save()
newOwnerAccount.save()
oldOwnerAccount.save();
token.save();
position.save()
transfer.save()
transfer.save();
}

0 comments on commit 43ca0dc

Please sign in to comment.