Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support deployment of unfunded ReleaseCelo contracts #11265

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions packages/protocol/scripts/truffle/deploy_release_contracts.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { celoRegistryAddress } from '@celo/protocol/lib/registry-utils'
import { _setInitialProxyImplementation, retryTx } from '@celo/protocol/lib/web3-utils'
import { retryTx, _setInitialProxyImplementation } from '@celo/protocol/lib/web3-utils'
import { Address, isValidAddress } from '@celo/utils/lib/address'
import BigNumber from 'bignumber.js'
import chalk from 'chalk'
Expand Down Expand Up @@ -42,6 +42,7 @@ interface ReleaseGoldConfig {
initialDistributionRatio: number
canValidate: boolean
canVote: boolean
fundGrant: boolean
}

type ReleaseGoldTemplate = Partial<ReleaseGoldConfig>
Expand Down Expand Up @@ -103,10 +104,14 @@ async function handleGrant(config: ReleaseGoldConfig, currGrant: number) {
const message =
'Please review this grant before you deploy:\n\tTotal Grant Value: ' +
Number(config.numReleasePeriods) * Number(config.amountReleasedPerPeriod) +
'\n\tGrant Actually Funded: ' +
(config.fundGrant ? 'YES' : 'NO') +
'\n\tGrant Recipient ID: ' +
config.identifier +
'\n\tGrant Beneficiary address: ' +
config.beneficiary +
'\n\tGrant Release owner: ' +
config.releaseOwner +
'\n\tGrant Start Date (Unix timestamp): ' +
Math.floor(releaseStartTime) +
'\n\tGrant Cliff time (in seconds): ' +
Expand Down Expand Up @@ -175,7 +180,7 @@ async function handleGrant(config: ReleaseGoldConfig, currGrant: number) {
'ReleaseGold',
{
from: fromAddress,
value: totalValue.toFixed(),
value: config.fundGrant ? totalValue.toFixed() : null,
},
...contractInitializationArgs
)
Expand Down Expand Up @@ -231,7 +236,7 @@ async function checkBalance(config: ReleaseGoldConfig) {
web3.utils.toWei(config.amountReleasedPerPeriod.toString())
)
const grantDeploymentCost = weiAmountReleasedPerPeriod
.multipliedBy(config.numReleasePeriods)
.multipliedBy(config.fundGrant ? config.numReleasePeriods : 0)
.plus(ONE_CELO) // Tx Fees
.toFixed()
while (true) {
Expand Down Expand Up @@ -512,6 +517,7 @@ async function handleJSONFile(data) {
// We check the first grant here and use that as a template for all grants
// to verify the grant file is uniformly typed to hopefully avoid user errors.
const template = {
fundGrant: grants[0].fundGrant,
revocable: grants[0].revocable,
canVote: grants[0].canVote,
canValidate: grants[0].canValidate,
Expand All @@ -521,6 +527,7 @@ async function handleJSONFile(data) {
if (!argv.yesreally) {
grants.map((grant) => {
if (
grant.fundGrant !== template.fundGrant ||
grant.revocable !== template.revocable ||
grant.canVote !== template.canVote ||
grant.canValidate !== template.canValidate ||
Expand All @@ -529,7 +536,7 @@ async function handleJSONFile(data) {
) {
console.error(
chalk.red(
'Grants are not uniformly typed.\nWe expect all grants of a given JSON to have the same boolean values for `revocable`, `canVote`, `canValidate`, and `subjectToLiquidityProvision`, as well as having the same value for `initialDistributionRatio`.\nExiting'
'Grants are not uniformly typed.\nWe expect all grants of a given JSON to have the same boolean values for `fundGrant`, `revocable`, `canVote`, `canValidate`, and `subjectToLiquidityProvision`, as well as having the same value for `initialDistributionRatio`.\nExiting'
)
)
process.exit(0)
Expand All @@ -538,7 +545,11 @@ async function handleJSONFile(data) {
}

const totalValue = grants.reduce((sum: number, curr: any) => {
return sum + Number(curr.amountReleasedPerPeriod) * Number(curr.numReleasePeriods)
return (
sum +
1 +
(curr.fundGrant ? Number(curr.amountReleasedPerPeriod) * Number(curr.numReleasePeriods) : 0)
)
}, 0)
const fromBalance = new BigNumber(await web3.eth.getBalance(fromAddress))
if (!argv.yesreally) {
Expand Down
Loading