@@ -46,13 +46,31 @@ async function calculateGDPWithdraw(
46
46
let reserved_for_withdrawal = await getMappingValue ( "2u8" , pondoProtocolProgramId , "balances" ) ;
47
47
let reservedForWithdrawal = convertToNumber ( reserved_for_withdrawal ) ;
48
48
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 ) ;
51
51
let grantee_paleo_balance = formattedGrantJson . paleo_amount ;
52
52
let granteePaleoBalance = convertToNumber ( grantee_paleo_balance ) ;
53
53
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 ) ;
56
74
}
57
75
58
76
calculateGDPWithdraw ( parseInt ( grant_num ) , programId ) ;
0 commit comments