Skip to content

Commit

Permalink
feat(claiming): calculate vesting with cliff
Browse files Browse the repository at this point in the history
  • Loading branch information
Tommytrg committed Oct 4, 2020
1 parent e97bb1c commit d07cf5a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
10 changes: 5 additions & 5 deletions claiming_file_success.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"data": {
"email_address": "asdf@gmail.com",
"email_address": "aaaaaaa.com",
"name": "asdf",
"source": "tip",
"usd": 0,
"wit": 784654841545,
"wit": 67556739024111000,
"vesting": {
"delay": 0,
"cliff": 1209600,
"installment_length": 1209600,
"installment_wits": 65387903462
"cliff": 15552000,
"installment_length": 1296000,
"installment_wits": 1407432063002312
},
"genesis_date": 1602666000
},
Expand Down
26 changes: 20 additions & 6 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -541,22 +541,36 @@ export function validateClaimingImportFile(importedFile) {

export function calculateVesting(vestingInfo, amount, genesisDate) {
const { delay, installmentLength, cliff, installmentWits } = vestingInfo
const numberOfSteps = Math.ceil(amount / installmentWits)
const result = Array(numberOfSteps)
const cliffSteps = Math.ceil(cliff / installmentLength)
const numberOfSteps = Math.ceil(amount / installmentWits) - cliffSteps

return Array(numberOfSteps)
.fill(0)
.map((_, index) => {
const date = new Date(genesisDate)
date.setSeconds(
date.getSeconds() + delay + cliff + installmentLength * index,
)
const currentAmount = amount >= installmentWits ? installmentWits : amount
amount -= installmentWits

let currentAmount
if (cliff && index === 0) {
if (amount >= installmentWits) {
currentAmount = installmentWits * cliffSteps
amount -= installmentWits * cliffSteps
} else {
currentAmount = amount
amount -= installmentWits
}
} else {
currentAmount = amount >= installmentWits ? installmentWits : amount
amount -= installmentWits
}

return {
date: date,
date,
amount: currentAmount,
}
})
return result
}

export function groupAmountByUnlockedDate(amount, base = 2) {
Expand Down

0 comments on commit d07cf5a

Please sign in to comment.