mirror of
https://github.com/logos-storage/codex-factory.git
synced 2026-01-02 13:03:07 +00:00
* chore: add package.json and package.lock to the project * build: add truffle configuration for contract deployment * feat: init swarm contracts and define migration script * feat: init bash scripts that orchestrate docker containers * fix: change auto-mining to progressing blockchain in order to satisfy bee ts check * chore: add npm command definitions and downgrade openzeppelin for solc ^0.6.0 * build: set solc compiler configuration similar to the original swarm deployment * chore: generate bee keys until 5 nodes * refactor: import erc20 logic from openzeppelin and remove sw3 contract because cannot produce same bytecode * chore: add trimmed single-swap-factory bytecode (without token address param) * feat: deploy erc20 and single swap factory contracts that bee also accepts * feat: bee.sh and blockchain.sh * feat: add supply script to fund bee overlay addresses * docs: amend README * docs: fix bee start command * fix: bee.sh datadir path * docs: add network script to the usage description * fix: solc compiler truffle config
86 lines
3.1 KiB
JavaScript
86 lines
3.1 KiB
JavaScript
const ERC20PresetMinterPauser = artifacts.require("ERC20PresetMinterPauser");
|
|
const beeAddresses = require('../bee-overlay-addresses.json')
|
|
|
|
function getRawTokenAmount(amount, decimals = 18) {
|
|
amount = web3.utils.toBN(amount)
|
|
const rawAmount = amount.mul(web3.utils.toBN(10).pow(web3.utils.toBN(decimals)))
|
|
return rawAmount
|
|
}
|
|
|
|
/** Supply given address with Ether */
|
|
async function supplyEther(recepientAddress, supplierAddress, etherAmount = "1") {
|
|
const transaction = await web3.eth.sendTransaction({
|
|
gasLimit: 6721975,
|
|
gasPrice: web3.utils.toWei('10', 'gwei'),
|
|
value: web3.utils.toWei(etherAmount),
|
|
from: supplierAddress,
|
|
to: recepientAddress
|
|
})
|
|
|
|
if(!transaction.status) {
|
|
console.error('Supply Ether Error', transaction)
|
|
throw new Error(`Error happened at supplying address ${recepientAddress} from account ${supplierAddress}`)
|
|
}
|
|
|
|
console.log(`Supplying address ${recepientAddress} with Ether from account ${supplierAddress} was successful! \n`
|
|
+ `\tGiven Ether Amount: ${etherAmount}\n`
|
|
+ `\tTransaction ID: ${transaction.transactionHash}`
|
|
)
|
|
console.log('-'.repeat(process.stdout.columns))
|
|
}
|
|
|
|
/** Supply given address with the given Token amount */
|
|
async function mintToken(recepientAddress, supplierAddress, tokenAddress, tokenAmount = "100") {
|
|
const instance = await ERC20PresetMinterPauser.at(tokenAddress)
|
|
const rawTokenAmount = getRawTokenAmount(tokenAmount)
|
|
const transaction = await instance.mint(
|
|
recepientAddress,
|
|
rawTokenAmount,
|
|
{
|
|
from: supplierAddress,
|
|
gasLimit: 6721975,
|
|
}
|
|
)
|
|
|
|
if(!transaction.receipt.status) {
|
|
console.error('Supply Token Error', transaction)
|
|
throw new Error(`Error happened at supplying address ${recepientAddress} from account ${supplierAddress}`)
|
|
}
|
|
|
|
console.log(`Supplying address ${recepientAddress} with Token from account ${supplierAddress} was successful! \n`
|
|
+ `\tGiven Token Amount: ${tokenAmount}\n`
|
|
+ `\tTransaction ID: ${transaction.tx}`,
|
|
)
|
|
console.log('-'.repeat(process.stdout.columns))
|
|
}
|
|
|
|
/** Supply ERC20 tokens to all configured Bee client overlay addresses */
|
|
async function supplyTokenForBees(supplierAddress, erc20ContractAddress) {
|
|
const txPromises = []
|
|
console.log(`Supply ERC20 tokens (${erc20ContractAddress}) to the configured Bee addresses`)
|
|
console.log('='.repeat(process.stdout.columns))
|
|
|
|
for(const beeAddress of beeAddresses) {
|
|
txPromises.push(mintToken(beeAddress, supplierAddress, erc20ContractAddress))
|
|
}
|
|
return Promise.all(txPromises)
|
|
}
|
|
|
|
/** Supply ether to all configured Bee client overlay addresses */
|
|
async function supplyEtherForBees(supplierAddress) {
|
|
const txPromises = []
|
|
console.log('Supply Ether to the configured Bee addresses')
|
|
console.log('='.repeat(process.stdout.columns))
|
|
|
|
for(const beeAddress of beeAddresses) {
|
|
txPromises.push(supplyEther(beeAddress, supplierAddress))
|
|
}
|
|
return Promise.all(txPromises)
|
|
}
|
|
|
|
module.exports = (async function(callback) {
|
|
const accounts = await web3.eth.getAccounts()
|
|
await supplyTokenForBees(accounts[0], ERC20PresetMinterPauser.address)
|
|
await supplyEtherForBees(accounts[0])
|
|
callback()
|
|
}); |