Skip to content

Commit fffd8f3

Browse files
committed
Add calculations for total withdraw
1 parent 613ea2a commit fffd8f3

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

pondo-bot/src/tests/scripts/calculateGDPWithdraw.ts

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,31 @@ async function calculateGDPWithdraw(
4646
let reserved_for_withdrawal = await getMappingValue("2u8", pondoProtocolProgramId, "balances");
4747
let reservedForWithdrawal = convertToNumber(reserved_for_withdrawal);
4848
let totalCreditsPool = delegatedCredits + coreProtocolAccount - reservedForWithdrawal;
49-
let grantee_credits_balance = formattedGrantJson.credits_amount;
50-
let granteeCreditsBalance = convertToNumber(grantee_credits_balance);
49+
let grantee_credits_amount = formattedGrantJson.credits_amount;
50+
let granteeCreditsAmount = convertToNumber(grantee_credits_amount);
5151
let grantee_paleo_balance = formattedGrantJson.paleo_amount;
5252
let granteePaleoBalance = convertToNumber(grantee_paleo_balance);
5353

54-
let maxWithdrawablePaleo = granteePaleoBalance - (granteeCreditsBalance * totalPaleoPool / totalCreditsPool);
55-
console.log("maxWithdrawablePaleo", maxWithdrawablePaleo);
54+
let maxWithdrawableRewardsPaleo = granteePaleoBalance - (granteeCreditsAmount * totalPaleoPool / totalCreditsPool);
55+
console.log("maxWithdrawableRewardsPaleo", maxWithdrawableRewardsPaleo);
56+
57+
let start_timestamp = formattedGrantJson.start_timestamp;
58+
let startTimestamp = convertToNumber(start_timestamp);
59+
console.log("startTimestamp", startTimestamp);
60+
let current_timestamp = await getMappingValue("0u8", "time_oracle.aleo", "timestamp");
61+
let currentTimestamp = convertToNumber(current_timestamp);
62+
console.log("currentTimestamp", currentTimestamp);
63+
let end_timestamp = formattedGrantJson.fully_vested_timestamp;
64+
let endTimestamp = convertToNumber(end_timestamp);
65+
66+
let timestampsSinceStart = currentTimestamp - startTimestamp;
67+
let totalVestingTimestamps = endTimestamp - startTimestamp;
68+
let vestedCredits = granteeCreditsAmount * timestampsSinceStart / totalVestingTimestamps;
69+
let boundedVestedCredits = vestedCredits < granteeCreditsAmount ? vestedCredits : granteeCreditsAmount;
70+
let minimumCreditsBalance = granteeCreditsAmount - boundedVestedCredits;
71+
console.log("minimumCreditsBalance", minimumCreditsBalance);
72+
let withdrawableTotalPaleo = granteePaleoBalance - (minimumCreditsBalance * totalPaleoPool / totalCreditsPool);
73+
console.log("withdrawableTotalPaleo", withdrawableTotalPaleo);
5674
}
5775

5876
calculateGDPWithdraw(parseInt(grant_num), programId);

0 commit comments

Comments
 (0)