Skip to content

Commit

Permalink
deploy-scripts: add a script for printing vesting
Browse files Browse the repository at this point in the history
  • Loading branch information
skozin committed Dec 17, 2020
1 parent d3b1c23 commit 553a4af
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 2 deletions.
4 changes: 2 additions & 2 deletions scripts/multisig/10-issue-tokens.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ async function issueTokens({ web3, artifacts }) {

const totalSupply = bigSum(amounts, vesting.unvestedTokensAmount)

log(` Total supply:`, chalk.yellow(totalSupply.toString()))
log(` Unvested tokens amount:`, chalk.yellow(vesting.unvestedTokensAmount))
log(` Total supply:`, chalk.yellow(web3.utils.fromWei(totalSupply.toString(), 'ether')))
log(` Unvested tokens amount:`, chalk.yellow(web3.utils.fromWei(vesting.unvestedTokensAmount, 'ether')))
log(` Token receivers (total ${chalk.yellow(holders.length)}):`)

holders.forEach((addr, i) => {
Expand Down
66 changes: 66 additions & 0 deletions scripts/multisig/print-vesting.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
const BN = require('bn.js')
const chalk = require('chalk')

const runOrWrapScript = require('../helpers/run-or-wrap-script')
const { log } = require('../helpers/log')
const { readNetworkState, assertRequiredNetworkState } = require('../helpers/persisted-network-state')

const REQUIRED_NET_STATE = ['vestingParams']

async function printVesting({ web3, artifacts }) {
const netId = await web3.eth.net.getId()

log.splitter()
log(`Network ID: ${chalk.yellow(netId)}`)

const state = readNetworkState(network.name, netId)
assertRequiredNetworkState(state, REQUIRED_NET_STATE)

log.splitter()

const { vestingParams: vesting } = state
const pairs = Object.entries(vesting.holders)

pairs.sort((pa, pb) =>
new BN(pa[1]).lt(new BN(pb[1])) ? 1 : -1
)

const holders = pairs.map(p => p[0])
const amounts = pairs.map(p => p[1])

log(`Vesting settings:`)
log(` Start:`, chalk.yellow(formatDate(vesting.start)))
log(` Cliff:`, chalk.yellow(formatDate(vesting.cliff)))
log(` End:`, chalk.yellow(formatDate(vesting.end)))
log(` Revokable:`, chalk.yellow(vesting.revokable))

const totalSupply = bigSum(amounts, vesting.unvestedTokensAmount)

log(` Token receivers (total ${chalk.yellow(holders.length)}):`)

holders.forEach((addr, i) => {
const amount = amounts[i]
const percentage = +new BN(amount).muln(10000).div(totalSupply) / 100
log(` ${addr}: ${chalk.yellow(web3.utils.fromWei(amount, 'ether'))} (${percentage}%)`)
})

const unvestedPercentage = +new BN(vesting.unvestedTokensAmount).muln(10000).div(totalSupply) / 100
log(` Unvested tokens amount: ${chalk.yellow(web3.utils.fromWei(vesting.unvestedTokensAmount, 'wei'))} (${unvestedPercentage}%)`)
log(` Total supply:`, chalk.yellow(web3.utils.fromWei(totalSupply.toString(), 'ether')))

log.splitter()
}

function bigSum(amounts, initialAmount = 0) {
const sum = new BN(initialAmount)
amounts.forEach(amount => {
sum.iadd(new BN(amount))
})
return sum
}

function formatDate(unixTimestamp) {
return new Date(unixTimestamp * 1000).toUTCString()
}

module.exports = runOrWrapScript(printVesting, module)

0 comments on commit 553a4af

Please sign in to comment.