2021-04-23 16:16:35 +02:00
|
|
|
const ERC20PresetMinterPauser = artifacts.require("ERC20PresetMinterPauser");
|
|
|
|
|
const FS = require('fs')
|
|
|
|
|
const Path = require('path')
|
|
|
|
|
|
2021-05-20 17:41:57 +02:00
|
|
|
function prefixedAddressParamToByteCode(address) {
|
|
|
|
|
// the first 2 chars removal removes 0x prefix
|
|
|
|
|
return address.substring(2).toLowerCase().padStart(64, '0')
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-21 16:10:55 +02:00
|
|
|
function intToByteCode(intParam) {
|
|
|
|
|
return Number(intParam).toString(16).padStart(64, '0')
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-23 16:16:35 +02:00
|
|
|
function getSimpleSwapFactoryBin(tokenAddress) {
|
2021-05-20 17:41:57 +02:00
|
|
|
const binPath = Path.join(__dirname, '..', 'contracts', 'SimpleSwapFactory.bytecode')
|
|
|
|
|
const bin = FS.readFileSync(binPath, 'utf8').toString()
|
|
|
|
|
tokenAddress = prefixedAddressParamToByteCode(tokenAddress)
|
2021-04-23 16:16:35 +02:00
|
|
|
//add tokenaddress for param to the end of the bytecode
|
2021-05-20 17:41:57 +02:00
|
|
|
return bin + tokenAddress
|
2021-04-23 16:16:35 +02:00
|
|
|
}
|
|
|
|
|
|
2021-05-20 17:41:57 +02:00
|
|
|
function getPostageStampBin(tokenAddress) {
|
|
|
|
|
const binPath = Path.join(__dirname, '..', 'contracts', 'PostageStamp.bytecode')
|
|
|
|
|
const bin = FS.readFileSync(binPath, 'utf8').toString()
|
|
|
|
|
tokenAddress = prefixedAddressParamToByteCode(tokenAddress)
|
|
|
|
|
//add tokenaddress for param to the end of the bytecode
|
|
|
|
|
return bin + tokenAddress
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-21 16:10:55 +02:00
|
|
|
function getPriceOracleBin(price, chequeValueDeduction) {
|
|
|
|
|
const binPath = Path.join(__dirname, '..', 'contracts', 'PriceOracle.bytecode')
|
|
|
|
|
const bin = FS.readFileSync(binPath, 'utf8').toString()
|
|
|
|
|
const priceAbi = intToByteCode(price)
|
|
|
|
|
const chequeValueAbi = intToByteCode(chequeValueDeduction)
|
|
|
|
|
//add tokenaddress for param to the end of the bytecode
|
|
|
|
|
return bin + priceAbi + chequeValueAbi
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-20 17:41:57 +02:00
|
|
|
/** Returns back contract hash */
|
|
|
|
|
async function createContract(contractName, data, creatorAccount) {
|
2021-04-23 16:16:35 +02:00
|
|
|
const transaction = await web3.eth.sendTransaction({
|
2021-05-20 17:41:57 +02:00
|
|
|
data: data,
|
2021-04-23 16:16:35 +02:00
|
|
|
gasLimit: 6721975,
|
|
|
|
|
gasPrice: web3.utils.toWei('10', 'gwei'),
|
|
|
|
|
from: creatorAccount
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
if(!transaction.status) {
|
2021-05-20 17:41:57 +02:00
|
|
|
console.error(`${contractName} contract creation Error`, error)
|
|
|
|
|
throw new Error(`Error happened at creating ${contractName} contract creation`)
|
2021-04-23 16:16:35 +02:00
|
|
|
}
|
2021-05-20 17:41:57 +02:00
|
|
|
console.log(`${contractName} contract creation was successful!\n`
|
2021-04-23 16:16:35 +02:00
|
|
|
+ `\tTransaction ID: ${transaction.transactionHash}\n`
|
|
|
|
|
+ `\tContract ID: ${transaction.contractAddress}`)
|
2021-05-20 17:41:57 +02:00
|
|
|
|
|
|
|
|
return transaction.contractAddress
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function createSimpleSwapFactoryContract(erc20ContractAddress, creatorAccount) {
|
|
|
|
|
return createContract('SimpleSwapFactory', getSimpleSwapFactoryBin(erc20ContractAddress), creatorAccount)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function createPostageStampContract(erc20ContractAddress, creatorAccount) {
|
|
|
|
|
return createContract('PostageStamp', getPostageStampBin(erc20ContractAddress), creatorAccount)
|
2021-04-23 16:16:35 +02:00
|
|
|
}
|
|
|
|
|
|
2021-06-21 16:10:55 +02:00
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @param {number} price current price in PLUR per accounting unit
|
|
|
|
|
* @param {number} chequeValueDeduction value deducted from first received cheque from a peer in PLUR
|
|
|
|
|
* @param {string} creatorAccount
|
|
|
|
|
*/
|
|
|
|
|
async function createPriceOracleContract(price, chequeValueDeduction, creatorAccount) {
|
|
|
|
|
return createContract('PriceOracle', getPriceOracleBin(price, chequeValueDeduction), creatorAccount)
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-23 16:16:35 +02:00
|
|
|
module.exports = function (deployer, network, accounts) {
|
|
|
|
|
deployer.deploy(ERC20PresetMinterPauser, "Swarm Token", "BZZ").then(async () => {
|
|
|
|
|
await createSimpleSwapFactoryContract(ERC20PresetMinterPauser.address, accounts[0])
|
2021-05-20 17:41:57 +02:00
|
|
|
await createPostageStampContract(ERC20PresetMinterPauser.address, accounts[0])
|
2021-06-21 16:10:55 +02:00
|
|
|
await createPriceOracleContract(100000, 1, accounts[0])
|
2021-04-23 16:16:35 +02:00
|
|
|
});
|
|
|
|
|
};
|