Skip to content

fix: tickets linking and origin when exiting commission during exitRequest #56

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 28 additions & 8 deletions src/ERC20.mapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -545,14 +545,34 @@ export function handleExit(event: Exit): void {
totalETH = totalETH.plus(ethValue);
depositDataEntry.exitedEth = depositDataEntry.exitedEth.plus(ethValue);
const exitQueue = vExitQueue.load(pool!.exitQueue);
const nextTicketIdx = exitQueue!.ticketCount.minus(BigInt.fromI32(details.length - idx));
const linkedTicketId = externalEntityUUID(Address.fromBytes(exitQueue!.address), [nextTicketIdx.toString()]);
tickets.push(linkedTicketId);

const ticket = Ticket.load(linkedTicketId);
if (ticket != null) {
ticket.origin = event.address;
ticket.save();

// Verify that the last ticket is owned by the staker, if not commissionShares were exited
// and we need to set the origin of the last tickets to the event emitter address
const staker = event.params.staker;
const lastTicketIdx = exitQueue!.ticketCount.minus(BigInt.fromI32(1));
const lastTicketId = externalEntityUUID(Address.fromBytes(exitQueue!.address), [lastTicketIdx.toString()]);
tickets.push(lastTicketId);

const lastTicket = Ticket.load(lastTicketId);
// I acknowledge that there is an edge case if a the last commission recipient is also the staker
// Fee recipients are generally not used to stake so it's unlikely we hit both edge cases at the same time
if (lastTicket != null && lastTicket!.owner.equals(staker)) {
lastTicket.origin = event.address;
lastTicket.save();
} else if (lastTicket != null) {
// We go back through the last tickets until we find one that has an origin set
// on the way we set the origin to the event address
let previousTicketIdx = lastTicketIdx.minus(BigInt.fromI32(1));
let previousTicketId = externalEntityUUID(Address.fromBytes(exitQueue!.address), [previousTicketIdx.toString()]);
let ticket = Ticket.load(previousTicketId);
while (ticket != null && ticket.origin == null) {
ticket.origin = event.address;
ticket.save();
tickets.push(previousTicketId);
previousTicketIdx = previousTicketIdx.minus(BigInt.fromI32(1));
previousTicketId = externalEntityUUID(Address.fromBytes(exitQueue!.address), [previousTicketIdx.toString()]);
ticket = Ticket.load(previousTicketId);
}
}
}

Expand Down
Loading