function _cancelVouchInternal(address staker, address borrower) internal {
Index memory removeVoucherIndex = voucherIndexes[borrower][staker];
if (!removeVoucherIndex.isSet) revert VoucherNotFound();
// Check that the locked amount for this vouch is 0
Vouch memory vouch = vouchers[borrower][removeVoucherIndex.idx];
if (vouch.locked > 0) revert LockedStakeNonZero();
// Remove borrower from vouchers array by moving the last item into the position
// of the index being removed and then poping the last item off the array
{
// Cache the last voucher
Vouch memory lastVoucher = vouchers[borrower][vouchers[borrower].length - 1];
// Move the lastVoucher to the index of the voucher we are removing
vouchers[borrower][removeVoucherIndex.idx] = lastVoucher;
// Pop the last vouch off the end of the vouchers array
vouchers[borrower].pop();
// Delete the voucher index for this borrower => staker pair
delete voucherIndexes[borrower][staker];
// Update the last vouchers coresponsing Vouchee item
uint128 voucheeIdx = voucherIndexes[borrower][lastVoucher.staker].idx;
vouchees[staker][voucheeIdx].voucherIndex = removeVoucherIndex.idx.toUint96();
}
// Update the vouchee entry for this borrower => staker pair
{
Index memory removeVoucheeIndex = voucheeIndexes[borrower][staker];
// Cache the last vouchee
Vouchee memory lastVouchee = vouchees[staker][vouchees[staker].length - 1];
// Move the last vouchee to the index of the removed vouchee
vouchees[staker][removeVoucheeIndex.idx] = lastVouchee;
// Pop the last vouchee off the end of the vouchees array
vouchees[staker].pop();
// Delete the vouchee index for this borrower => staker pair
delete voucheeIndexes[borrower][staker];
// Update the vouchee indexes to the new vouchee index
voucheeIndexes[lastVouchee.borrower][staker].idx = removeVoucheeIndex.idx;
}
emit LogCancelVouch(staker, borrower);
}
/**
* Cancels a vouch between a staker and a borrower.
* @dev The function can only be called by a member of the stakers list.
* @param staker The address of the staker who made the vouch.
* @param borrower The address of the borrower who received the vouch.
*/
function cancelVouch(address staker, address borrower) public onlyMember(msg.sender) whenNotPaused {
if (staker != msg.sender && borrower != msg.sender) revert AuthFailed();
_cancelVouchInternal(staker, borrower);
}