Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@superfluid-finance/dashboard",
"version": "14.0.0",
"version": "15.0.0",
"private": true,
"type": "module",
"scripts": {
Expand Down
17 changes: 10 additions & 7 deletions src/features/pendingUpdates/PendingVestingSchedule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ export const mapPendingToVestingSchedule = (
? cliffDateTimestamp
: startDateTimestamp;

const totalAmount = calculateVestingScheduleAllocated(
cliffAndFlowDate,
endDateTimestamp,
flowRateWei,
cliffTransferAmountWei,
"0"
).toString();

return {
pendingCreate: pendingVestingSchedule,
id: `${superTokenAddress}-${address}-${receiverAddress}-${version}-${pendingVestingSchedule.transactionHash}`,
Expand All @@ -90,12 +98,7 @@ export const mapPendingToVestingSchedule = (
remainderAmount: "0",
version,
transactionHash: pendingVestingSchedule.transactionHash,
totalAmount: calculateVestingScheduleAllocated(
cliffAndFlowDate,
endDateTimestamp,
flowRateWei,
cliffTransferAmountWei,
"0"
).toString(),
totalAmount,
totalAmountWithOverpayment: totalAmount, // For pending schedules, there's no overpayment yet
};
};
42 changes: 41 additions & 1 deletion src/features/vesting/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
} from "../../vesting-subgraph/.graphclient";
import { dateNowSeconds } from "../../utils/dateUtils";
import { VestingVersion } from "../network/networkConstants";
import { BigNumber } from "ethers";

interface VestingStatus {
title: string;
Expand Down Expand Up @@ -153,6 +154,7 @@ export interface VestingSchedule {
version: VestingVersion;
transactionHash: string;
totalAmount: string;
totalAmountWithOverpayment: string;
}

export type SubgraphVestingSchedule = NonNullable<
Expand Down Expand Up @@ -200,13 +202,51 @@ export const mapSubgraphVestingSchedule = (
transactionHash: vestingSchedule.id.split("-")[0],
totalAmount: vestingSchedule.totalAmount
};

const totalAmountWithOverpayment = calculateTotalAmountWithOverpayment(mappedVestingSchedule);

return {
...mappedVestingSchedule,
totalAmountWithOverpayment,
status: getVestingStatus(mappedVestingSchedule),
};
};

const getVestingStatus = (vestingSchedule: Omit<VestingSchedule, "status">) => {
const calculateTotalAmountWithOverpayment = (
vestingSchedule: Omit<VestingSchedule, "status" | "totalAmountWithOverpayment">
): string => {
const {
totalAmount,
remainderAmount,
flowRate,
cliffAndFlowExecutedAt,
endExecutedAt,
endDate
} = vestingSchedule;

// Default to totalAmount
if (!cliffAndFlowExecutedAt || !endExecutedAt || !endDate) {
return totalAmount;
}

// Check if the vesting schedule was overpaid
if (cliffAndFlowExecutedAt < endDate && endExecutedAt > endDate) {
// Calculate: totalAmount - remainderAmount + (endExecutedAt - endDate) * flowRate
const overpaymentSeconds = endExecutedAt - endDate;
const overpaymentAmount = BigNumber.from(overpaymentSeconds).mul(flowRate);
const totalAmountBN = BigNumber.from(totalAmount);
const remainderAmountBN = BigNumber.from(remainderAmount);

return totalAmountBN
.sub(remainderAmountBN)
.add(overpaymentAmount)
.toString();
}

return totalAmount;
};

const getVestingStatus = (vestingSchedule: Omit<VestingSchedule, "status" | "totalAmountWithOverpayment">) => {
const {
deletedAt,
failedAt,
Expand Down
4 changes: 2 additions & 2 deletions src/pages/api/agora.ts
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ export default async function handler(
const agoraCurrentAmount_ = row.amounts[row.amounts.length - 1] ?? 0;
const agoraCurrentAmount = BigInt(agoraCurrentAmount_);
const agoraTotalAmount = row.amounts.reduce((sum, amount) => sum + BigInt(amount || 0), 0n);
const subgraphTotalAmount = allRelevantVestingSchedules.reduce((sum, vestingSchedule) => sum + BigInt(vestingSchedule.totalAmount ?? 0), 0n);
const subgraphTotalAmount = allRelevantVestingSchedules.reduce((sum, vestingSchedule) => sum + BigInt(vestingSchedule.totalAmountWithOverpayment ?? 0), 0n);
const missingAmount = agoraTotalAmount - subgraphTotalAmount;

const actions = yield* E.gen(function* () {
Expand Down Expand Up @@ -540,7 +540,7 @@ export default async function handler(
})
}

const isFundingJustChangedForProject = agoraTotalAmount !== subgraphTotalAmount;
const isFundingJustChangedForProject = agoraTotalAmount > subgraphTotalAmount;

if (isFundingJustChangedForProject) {
if (agoraCurrentAmount === 0n) {
Expand Down
3 changes: 2 additions & 1 deletion src/pages/vesting/[_network]/[_id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export type VestingActivities = (
| Activity<VestingScheduleCreatedEvent>
| Activity<VestingScheduleDeletedEvent>
| Activity<VestingClaimedEvent>
| Activity<VestingScheduleDeletedEvent>
)[];

const VestingScheduleDetailsPage: NextPageWithLayout = () => {
Expand Down Expand Up @@ -249,7 +250,7 @@ const VestingScheduleDetailsContent: FC<VestingScheduleDetailsContentProps> = ({
vestingSchedule.sender,
vestingSchedule.receiver,
],
name_in: ["VestingScheduleCreatedEvent", "VestingScheduleUpdatedEvent", "VestingClaimedEvent"],
name_in: ["VestingScheduleCreatedEvent", "VestingScheduleUpdatedEvent", "VestingClaimedEvent", "VestingScheduleDeletedEvent"],
timestamp_gte: vestingSchedule.createdAt.toString(),
timestamp_lte:
vestingSchedule.deletedAt
Expand Down
13 changes: 10 additions & 3 deletions src/utils/vestingUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,13 +221,20 @@ export function vestingScheduleToTokenBalance(
cliffAndFlowDate,
didEarlyEndCompensationFail,
earlyEndCompensation,
failedAt,
deletedAt,
remainderAmount,
claimedAt
claimedAt,
claimValidityDate
} = vestingSchedule;

if (failedAt) return null;
// If the vesting schedule was deleted and not claimed (when claimable), return 0 balance
if (deletedAt && claimValidityDate && !claimedAt) {
return {
balance: "0",
totalNetFlowRate: "0",
timestamp: deletedAt,
};
}

const wasClaimedAfterEndDate = (claimedAt ?? 0) > endDate;
const effectiveEndAt = (wasClaimedAfterEndDate ? endDate : undefined) || endExecutedAt || deletedAt;
Expand Down
Loading