-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathPendingVestingSchedule.ts
More file actions
104 lines (97 loc) · 3.13 KB
/
PendingVestingSchedule.ts
File metadata and controls
104 lines (97 loc) · 3.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import { useMemo } from "react";
import { PendingUpdate } from "./PendingUpdate";
import { pendingUpdateSelectors } from "./pendingUpdate.slice";
import { useAppSelector } from "../redux/store";
import { CreateVestingSchedule } from "../redux/endpoints/vestingSchedulerEndpoints";
import { Address } from "@superfluid-finance/sdk-core";
import { VestingSchedule, vestingStatuses } from "../vesting/types";
import { calculateVestingScheduleAllocated } from "../../utils/vestingUtils";
export interface PendingVestingSchedule
extends PendingUpdate,
Pick<
CreateVestingSchedule,
| "chainId"
| "superTokenAddress"
| "senderAddress"
| "receiverAddress"
| "startDateTimestamp"
| "cliffDateTimestamp"
| "flowRateWei"
| "endDateTimestamp"
| "cliffTransferAmountWei"
| "version"
> {
pendingType: "VestingScheduleCreate";
}
export const isPendingVestingSchedule = (
x: PendingUpdate
): x is PendingVestingSchedule => x.pendingType === "VestingScheduleCreate";
export const useAddressPendingVestingSchedules = (
address: string | undefined
): PendingVestingSchedule[] => {
const allPendingUpdates = useAppSelector((state) =>
pendingUpdateSelectors.selectAll(state.pendingUpdates)
);
return useMemo(
() =>
address
? allPendingUpdates
.filter(isPendingVestingSchedule)
.filter(
(x) => x.senderAddress.toLowerCase() === address.toLowerCase()
)
: [],
[address, allPendingUpdates]
);
};
export const mapPendingToVestingSchedule = (
address: Address,
pendingVestingSchedule: PendingVestingSchedule
): VestingSchedule & { pendingCreate: PendingVestingSchedule } => {
const {
cliffDateTimestamp,
cliffTransferAmountWei,
endDateTimestamp,
receiverAddress,
startDateTimestamp,
superTokenAddress,
flowRateWei,
version
} = pendingVestingSchedule;
const cliffAndFlowDate = cliffDateTimestamp
? cliffDateTimestamp
: startDateTimestamp;
const totalAmount = calculateVestingScheduleAllocated(
cliffAndFlowDate,
endDateTimestamp,
flowRateWei,
cliffTransferAmountWei,
"0"
).toString();
return {
pendingCreate: pendingVestingSchedule,
id: `${superTokenAddress}-${address}-${receiverAddress}-${version}-${pendingVestingSchedule.transactionHash}`,
superToken: superTokenAddress,
sender: address,
receiver: receiverAddress,
flowRate: flowRateWei,
createdAt: pendingVestingSchedule.timestamp,
startDate: startDateTimestamp,
cliffDate: cliffDateTimestamp,
cliffAmount: cliffTransferAmountWei,
endDateValidAt: endDateTimestamp,
endDate: endDateTimestamp,
cliffAndFlowDate: cliffAndFlowDate,
cliffAndFlowExpirationAt: cliffAndFlowDate,
didEarlyEndCompensationFail: false,
earlyEndCompensation: "0",
failedAt: undefined,
status: vestingStatuses.ScheduledStart,
claimValidityDate: 0,
remainderAmount: "0",
version,
transactionHash: pendingVestingSchedule.transactionHash,
totalAmount,
totalAmountWithOverpayment: totalAmount, // For pending schedules, there's no overpayment yet
};
};