{"size": 2132, "ext": "js", "max_stars_repo_path": "eth-contracts/migrations/4_token_migration.js", "max_stars_repo_name": "Tenderize/audius-protocol", "max_stars_repo_stars_event_min_datetime": "2019-08-14T01:34:07.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T06:31:38.000Z", "max_issues_repo_path": "eth-contracts/migrations/4_token_migration.js", "max_issues_repo_name": "Tenderize/audius-protocol", "max_issues_repo_issues_event_min_datetime": "2019-08-14T01:52:37.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T23:17:22.000Z", "max_forks_repo_path": "eth-contracts/migrations/4_token_migration.js", "max_forks_repo_name": "Tenderize/audius-protocol", "max_forks_repo_forks_event_min_datetime": "2019-10-04T04:24:16.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T16:27:30.000Z"}
{"max_stars_count": 429, "max_issues_count": 998, "max_forks_count": 73, "avg_line_length": 37.4035087719, "max_line_length": 93, "alphanum_fraction": 0.7467166979}
const contractConfig = require('../contract-config.js')
const _lib = require('../utils/lib')
const assert = require('assert')

const AudiusToken = artifacts.require('AudiusToken')
const AudiusAdminUpgradeabilityProxy = artifacts.require('AudiusAdminUpgradeabilityProxy')
const Governance = artifacts.require('Governance')

const tokenRegKey = web3.utils.utf8ToHex('Token')

const INITIAL_SUPPLY = Math.pow(10,27)

module.exports = (deployer, network, accounts) => {
  deployer.then(async () => {
    const config = contractConfig[network]
    const proxyAdminAddress = config.proxyAdminAddress || accounts[10]
    const proxyDeployerAddress = config.proxyDeployerAddress || accounts[11]
    const guardianAddress = config.guardianAddress || proxyDeployerAddress
    const tokenOwnerAddress = proxyDeployerAddress

    const governanceAddress = process.env.governanceAddress
    const governance = await Governance.at(governanceAddress)

    // Deploy AudiusToken logic and proxy contracts
    const token0 = await deployer.deploy(AudiusToken, { from: proxyDeployerAddress })
    const initializeCallData = _lib.encodeCall(
      'initialize',
      ['address', 'address'],
      [tokenOwnerAddress, governanceAddress]
    )
    const tokenProxy = await deployer.deploy(
      AudiusAdminUpgradeabilityProxy,
      token0.address,
      governanceAddress,
      initializeCallData,
      { from: proxyDeployerAddress }
    )
    const token = await AudiusToken.at(tokenProxy.address)

    // Register token
    await _lib.registerContract(governance, tokenRegKey, tokenProxy.address, guardianAddress)

    // Confirm initial token supply
    assert.equal(await token.totalSupply.call(), INITIAL_SUPPLY)

    // Confirm total supply is in owner account
    assert.equal(await token.balanceOf.call(tokenOwnerAddress), INITIAL_SUPPLY)

    // Confirm governance has minter & pauser roles
    assert.equal(await token.isMinter.call(governanceAddress), true)
    assert.equal(await token.isMinter.call(tokenOwnerAddress), false)

    // Export to env for reference in future migrations
    process.env.tokenAddress = token.address
  })
}
