-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathlib.ts
75 lines (60 loc) · 1.96 KB
/
lib.ts
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
import { BigNumber } from "@ethersproject/bignumber";
import { parseEther } from "@ethersproject/units";
import { underline } from "chalk";
import {
CandleGeniePredictionV3,
PancakePredictionV2,
} from "./types/typechain";
// Utility Function to use **await sleep(ms)**
export const sleep = (ms: number) =>
new Promise((resolve) => setTimeout(resolve, ms));
export const reduceWaitingTimeByTwoBlocks = (waitingTime: number) => {
if (waitingTime <= 6000) {
return waitingTime;
}
return waitingTime - 6000;
};
export const getClaimableEpochs = async (
predictionContract: PancakePredictionV2,
epoch: BigNumber,
userAddress: string
) => {
const claimableEpochs: BigNumber[] = [];
for (let i = 1; i <= 5; i++) {
const epochToCheck = epoch.sub(i);
const [claimable, refundable, { claimed, amount }] = await Promise.all([
predictionContract.claimable(epochToCheck, userAddress),
predictionContract.refundable(epochToCheck, userAddress),
predictionContract.ledger(epochToCheck, userAddress),
]);
if (amount.gt(0) && (claimable || refundable) && !claimed) {
claimableEpochs.push(epochToCheck);
}
}
return claimableEpochs;
};
export const calcRets = (amount: BigNumber | undefined) => {
if (!amount || amount.div(25).lt(parseEther("0.004"))) {
return parseEther("0.004");
}
return amount.div(25);
};
export const getClaimableEpochsCG = async (
predictionContract: CandleGeniePredictionV3,
epoch: BigNumber,
userAddress: string
) => {
const claimableEpochs: BigNumber[] = [];
for (let i = 1; i <= 5; i++) {
const epochToCheck = epoch.sub(i);
const [claimable, refundable, { claimed, amount }] = await Promise.all([
predictionContract.claimable(epochToCheck, userAddress),
predictionContract.refundable(epochToCheck, userAddress),
predictionContract.Bets(epochToCheck, userAddress),
]);
if (amount.gt(0) && (claimable || refundable) && !claimed) {
claimableEpochs.push(epochToCheck);
}
}
return claimableEpochs;
};