134 lines
4.9 KiB
JavaScript
Raw Normal View History

const ERC20PresetMinterPauser = artifacts.require('ERC20PresetMinterPauser')
const FS = require('fs')
const Path = require('path')
const NETWORK_ID = 4020
function prefixedAddressParamToByteCode(address) {
// the first 2 chars removal removes 0x prefix
return address.substring(2).toLowerCase().padStart(64, '0')
}
feat: bee 1.0.0 (#41) * feat: new Price Oracle bytecode * refactor: remove file smth.txt * feat: new PostageStamp contract * feat: change contract deploy workflow * feat: bee-1.0.0-rc2 compatible runner * feat: build from source (#47) * feat: extend build-envrionment.sh with building bee image from source * ci: new workflow option parameter - beeVersionAsCommitHash * fix(ci): try to overwrite BEE_VERSION sys variable * fix: do not export BEE_VERSION after env build * fix(ci): run build-environment without source command * fix(ci): try to retrieve built BEE_VERSION value * fix: save build BEE_VERSION value * fix(ci): retrieve built image tag in the last step * refactor: echoerr * refactor(ci): export sys variables * feat: disable warmup time (#46) * feat: disable warmup time * fix: place warmup-time to the correct place * fix: put quote back where it truly belongs * feat: state commit (#45) * refactor: remove payment treshold option because it causes performance issues * docs: design planned parameters for the new build workflow * feat: build environment with traffic gen option * fix(log): rephrase traffic gen log * feat: special bee version tagging when state commit happens * build: new env variable STATE_COMMIT * ci: STATE_COMMIT * feat: state commit scripts * refactor: destroy containers after state producing * refactor: remove unnecessary echo * fix: blockchain version at state commit * build: bumo bee-js version * build: update package-lock * fix: fixes * ci: build environment workflow with state commit * refactor: buy larger stamp * fix: publish workflow * refactor: increase stamp depth * fix: bee version fetch at commit * refactor: start containers normally instead of ephemeral for debugging * fix(ci): add chown for bee user on bee-data-dirs in order to write bee state * fix: try out the permission on bee data dir with 777 chmod * fix(ci): give folder permission in the build environment phrase * refactor(ci): raise sleep between uploads in order to generate cheques * refactor: wait 11 secs after batch purchase * fix: commit version tag string true instead of boolean * fix: add state commit check for set COMMIT_VERSION_TAG * chore: bump bee version Co-authored-by: Cafe137 <77121044+Cafe137@users.noreply.github.com>
2021-06-21 16:10:55 +02:00
function intToByteCode(intParam) {
return Number(intParam).toString(16).padStart(64, '0')
}
function getSimpleSwapFactoryBin(tokenAddress) {
const binPath = Path.join(__dirname, '..', 'contracts', 'SimpleSwapFactory.bytecode')
const bin = FS.readFileSync(binPath, 'utf8').toString().trim()
tokenAddress = prefixedAddressParamToByteCode(tokenAddress)
//add tokenaddress for param to the end of the bytecode
return bin + tokenAddress
}
function getPostageStampBin(tokenAddress) {
const binPath = Path.join(__dirname, '..', 'contracts', 'PostageStamp.bytecode')
const bin = FS.readFileSync(binPath, 'utf8').toString().trim()
tokenAddress = prefixedAddressParamToByteCode(tokenAddress)
//add tokenaddress for param to the end of the bytecode
return bin + tokenAddress
}
2022-12-14 01:49:32 -08:00
function getPostagePriceOracleBin(tokenAddress) {
const binPath = Path.join(__dirname, '..', 'contracts', 'PostagePriceOracle.bytecode')
const bin = FS.readFileSync(binPath, 'utf8').toString().trim()
tokenAddress = prefixedAddressParamToByteCode(tokenAddress)
//add tokenaddress for param to the end of the bytecode
return bin + tokenAddress
}
function getSwapPriceOracleBin(price, chequeValueDeduction) {
const binPath = Path.join(__dirname, '..', 'contracts', 'SwapPriceOracle.bytecode')
const bin = FS.readFileSync(binPath, 'utf8').toString().trim()
feat: bee 1.0.0 (#41) * feat: new Price Oracle bytecode * refactor: remove file smth.txt * feat: new PostageStamp contract * feat: change contract deploy workflow * feat: bee-1.0.0-rc2 compatible runner * feat: build from source (#47) * feat: extend build-envrionment.sh with building bee image from source * ci: new workflow option parameter - beeVersionAsCommitHash * fix(ci): try to overwrite BEE_VERSION sys variable * fix: do not export BEE_VERSION after env build * fix(ci): run build-environment without source command * fix(ci): try to retrieve built BEE_VERSION value * fix: save build BEE_VERSION value * fix(ci): retrieve built image tag in the last step * refactor: echoerr * refactor(ci): export sys variables * feat: disable warmup time (#46) * feat: disable warmup time * fix: place warmup-time to the correct place * fix: put quote back where it truly belongs * feat: state commit (#45) * refactor: remove payment treshold option because it causes performance issues * docs: design planned parameters for the new build workflow * feat: build environment with traffic gen option * fix(log): rephrase traffic gen log * feat: special bee version tagging when state commit happens * build: new env variable STATE_COMMIT * ci: STATE_COMMIT * feat: state commit scripts * refactor: destroy containers after state producing * refactor: remove unnecessary echo * fix: blockchain version at state commit * build: bumo bee-js version * build: update package-lock * fix: fixes * ci: build environment workflow with state commit * refactor: buy larger stamp * fix: publish workflow * refactor: increase stamp depth * fix: bee version fetch at commit * refactor: start containers normally instead of ephemeral for debugging * fix(ci): add chown for bee user on bee-data-dirs in order to write bee state * fix: try out the permission on bee data dir with 777 chmod * fix(ci): give folder permission in the build environment phrase * refactor(ci): raise sleep between uploads in order to generate cheques * refactor: wait 11 secs after batch purchase * fix: commit version tag string true instead of boolean * fix: add state commit check for set COMMIT_VERSION_TAG * chore: bump bee version Co-authored-by: Cafe137 <77121044+Cafe137@users.noreply.github.com>
2021-06-21 16:10:55 +02:00
const priceAbi = intToByteCode(price)
const chequeValueAbi = intToByteCode(chequeValueDeduction)
//add tokenaddress for param to the end of the bytecode
return bin + priceAbi + chequeValueAbi
}
function getStakeRegistryBin(tokenAddress) {
const binPath = Path.join(__dirname, '..', 'contracts', 'StakeRegistry.bytecode')
const bin = FS.readFileSync(binPath, 'utf8').toString().trim()
tokenAddress = prefixedAddressParamToByteCode(tokenAddress)
const networkIdAbi = intToByteCode(NETWORK_ID)
//add tokenaddress and encoded network ID for param to the end of the bytecode
return bin + tokenAddress + networkIdAbi
}
2022-12-14 01:49:32 -08:00
function getRedistributionBin(stakingAddress, postageContractAddress, oracleContractAddress) {
const binPath = Path.join(__dirname, '..', 'contracts', 'Redistribution.bytecode')
const bin = FS.readFileSync(binPath, 'utf8').toString().trim()
stakingAddress = prefixedAddressParamToByteCode(stakingAddress)
postageContractAddress = prefixedAddressParamToByteCode(postageContractAddress)
2022-12-14 01:49:32 -08:00
oracleContractAddress = prefixedAddressParamToByteCode(oracleContractAddress)
//add staking address, postage address and oracle contract address for param to the end of the bytecode
return bin + stakingAddress + postageContractAddress + oracleContractAddress
}
/** Returns back contract hash */
async function createContract(contractName, data, creatorAccount, configName) {
const transaction = await web3.eth.sendTransaction({
data: data,
gasLimit: 6721975,
gasPrice: web3.utils.toWei('10', 'gwei'),
from: creatorAccount,
})
if (!transaction.status) {
console.error(`${contractName} contract creation Error`, error)
throw new Error(`Error happened at creating ${contractName} contract creation`)
}
console.log(
`${contractName} contract creation was successful!\n` +
`\tTransaction ID: ${transaction.transactionHash}\n` +
`\tContract ID: ${transaction.contractAddress}`,
)
2022-12-14 01:49:32 -08:00
if (configName) {
console.log(`::CONTRACT:${configName}:${transaction.contractAddress}\n`)
}
return transaction.contractAddress
}
module.exports = function (deployer, network, accounts) {
const creatorAccount = accounts[0]
deployer.deploy(ERC20PresetMinterPauser, 'Swarm Token', 'BZZ').then(async () => {
2022-12-14 01:49:32 -08:00
await createContract('SwapPriceOracle', getSwapPriceOracleBin(100000, 100), creatorAccount, 'price-oracle-address')
await createContract(
'SimpleSwapFactory',
getSimpleSwapFactoryBin(ERC20PresetMinterPauser.address),
creatorAccount,
'swap-factory-address',
)
const postageStampAddress = await createContract(
'PostageStamp',
getPostageStampBin(ERC20PresetMinterPauser.address),
creatorAccount,
'postage-stamp-address',
)
feat: bee 1.0.0 (#41) * feat: new Price Oracle bytecode * refactor: remove file smth.txt * feat: new PostageStamp contract * feat: change contract deploy workflow * feat: bee-1.0.0-rc2 compatible runner * feat: build from source (#47) * feat: extend build-envrionment.sh with building bee image from source * ci: new workflow option parameter - beeVersionAsCommitHash * fix(ci): try to overwrite BEE_VERSION sys variable * fix: do not export BEE_VERSION after env build * fix(ci): run build-environment without source command * fix(ci): try to retrieve built BEE_VERSION value * fix: save build BEE_VERSION value * fix(ci): retrieve built image tag in the last step * refactor: echoerr * refactor(ci): export sys variables * feat: disable warmup time (#46) * feat: disable warmup time * fix: place warmup-time to the correct place * fix: put quote back where it truly belongs * feat: state commit (#45) * refactor: remove payment treshold option because it causes performance issues * docs: design planned parameters for the new build workflow * feat: build environment with traffic gen option * fix(log): rephrase traffic gen log * feat: special bee version tagging when state commit happens * build: new env variable STATE_COMMIT * ci: STATE_COMMIT * feat: state commit scripts * refactor: destroy containers after state producing * refactor: remove unnecessary echo * fix: blockchain version at state commit * build: bumo bee-js version * build: update package-lock * fix: fixes * ci: build environment workflow with state commit * refactor: buy larger stamp * fix: publish workflow * refactor: increase stamp depth * fix: bee version fetch at commit * refactor: start containers normally instead of ephemeral for debugging * fix(ci): add chown for bee user on bee-data-dirs in order to write bee state * fix: try out the permission on bee data dir with 777 chmod * fix(ci): give folder permission in the build environment phrase * refactor(ci): raise sleep between uploads in order to generate cheques * refactor: wait 11 secs after batch purchase * fix: commit version tag string true instead of boolean * fix: add state commit check for set COMMIT_VERSION_TAG * chore: bump bee version Co-authored-by: Cafe137 <77121044+Cafe137@users.noreply.github.com>
2021-06-21 16:10:55 +02:00
2022-12-14 01:49:32 -08:00
const postagePriceOracleAddress = await createContract(
'PostagePriceOracle',
getPostagePriceOracleBin(ERC20PresetMinterPauser.address),
creatorAccount,
)
const stakeRegistryAddress = await createContract(
'StakeRegistry',
2022-12-14 01:49:32 -08:00
getStakeRegistryBin(ERC20PresetMinterPauser.address),
creatorAccount,
'staking-address',
)
await createContract(
'Redistribution',
2022-12-14 01:49:32 -08:00
getRedistributionBin(stakeRegistryAddress, postageStampAddress, postagePriceOracleAddress),
creatorAccount,
'redistribution-address',
)
})
}