Merge pull request #10 from akolotov/decimals-shift
decimal shift for correct conversion ERC20 token to BEP2 token
This commit is contained in:
commit
3098b0ef80
|
@ -8,8 +8,8 @@ data/
|
|||
demo/validator*/db
|
||||
demo/validator*/keys
|
||||
demo/validator*/queue
|
||||
demo/ganache_data/
|
||||
demo/ganache_data_side/
|
||||
demo/ganache_home
|
||||
demo/ganache_side
|
||||
src/deploy/deploy-home/build/
|
||||
src/deploy/deploy-side/build/
|
||||
src/deploy/deploy-test/build/
|
||||
|
|
|
@ -4,11 +4,14 @@ set -e
|
|||
|
||||
cd $(dirname "$0")
|
||||
|
||||
rm -rf ganache_side_db
|
||||
rm -rf ganache_home_db
|
||||
|
||||
for (( I = 1; I < 4; ++I )); do
|
||||
DIRNAME="validator$I"
|
||||
rm -r "$DIRNAME/db"
|
||||
rm -r "$DIRNAME/queue"
|
||||
rm -r "$DIRNAME/keys"
|
||||
rm -rf "$DIRNAME/db"
|
||||
rm -rf "$DIRNAME/queue"
|
||||
rm -rf "$DIRNAME/keys"
|
||||
mkdir "$DIRNAME/db"
|
||||
mkdir "$DIRNAME/queue"
|
||||
mkdir "$DIRNAME/keys"
|
||||
|
|
|
@ -6,15 +6,29 @@ cd $(dirname "$0")
|
|||
|
||||
echo "Starting side test blockchain"
|
||||
|
||||
mntpoint=`pwd`/ganache_side_db
|
||||
if [ ! -d ${mntpoint} ]; then
|
||||
mkdir ${mntpoint}
|
||||
fi
|
||||
|
||||
docker kill ganache_side > /dev/null 2>&1 || true
|
||||
docker network create blockchain_side > /dev/null 2>&1 || true
|
||||
docker run -d --network blockchain_side --rm --name ganache_side trufflesuite/ganache-cli:latest -m "shrug dwarf easily blade trigger lucky reopen cage lake scatter desk boat" -i 33 -q
|
||||
docker run -d --network blockchain_side --rm --name ganache_side -v ${mntpoint}:/app/db \
|
||||
trufflesuite/ganache-cli:latest \
|
||||
-m "shrug dwarf easily blade trigger lucky reopen cage lake scatter desk boat" -i 33 -q --db /app/db
|
||||
|
||||
echo "Starting home test blockchain"
|
||||
|
||||
mntpoint=`pwd`/ganache_home_db
|
||||
if [ ! -d ${mntpoint} ]; then
|
||||
mkdir ${mntpoint}
|
||||
fi
|
||||
|
||||
docker kill ganache_home > /dev/null 2>&1 || true
|
||||
docker network create blockchain_home > /dev/null 2>&1 || true
|
||||
docker run -d --network blockchain_home --rm --name ganache_home trufflesuite/ganache-cli:latest -m "shrug dwarf easily blade trigger lucky reopen cage lake scatter desk boat" -i 44 -q
|
||||
docker run -d --network blockchain_home --rm --name ganache_home -v ${mntpoint}:/app/db \
|
||||
trufflesuite/ganache-cli:latest \
|
||||
-m "shrug dwarf easily blade trigger lucky reopen cage lake scatter desk boat" -i 44 -q --db /app/db
|
||||
|
||||
sleep 4
|
||||
|
||||
|
|
|
@ -3,3 +3,5 @@ RPC_URL_DEV=http://ganache_home:8545
|
|||
|
||||
PRIVATE_KEY=e49fe947f224ae8e126c41b1be3e52be701509c2366e835ea8c08651f91030e0
|
||||
PRIVATE_KEY_DEV=e2aeb24eaa63102d0c0821717c3b6384abdabd7af2ad4ec8e650dce300798b27
|
||||
|
||||
TOKEN_INITIAL_MINT=31415000000000000000000000
|
||||
|
|
|
@ -1,8 +1,12 @@
|
|||
const TokenContract = artifacts.require('ERC20Mintable')
|
||||
|
||||
const {
|
||||
TOKEN_INITIAL_MINT
|
||||
} = process.env
|
||||
|
||||
module.exports = async (deployer, network, accounts) => {
|
||||
await deployer.deploy(TokenContract)
|
||||
|
||||
const instance = await TokenContract.deployed()
|
||||
await instance.mint(accounts[0], 1000000)
|
||||
await instance.mint(accounts[0], TOKEN_INITIAL_MINT)
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ async function main () {
|
|||
await proxyHttpClient
|
||||
.post('/transfer', {
|
||||
to: computeAddress(Buffer.from(publicKeyEncoded, 'base64')),
|
||||
value: new BN(tx.value).integerValue(BN.ROUND_FLOOR),//(new BN(tx.value).multipliedBy(10 ** 8)).toNumber(),
|
||||
value: new BN(tx.value).multipliedBy(10 ** 18).integerValue(),
|
||||
hash: `0x${tx.txHash}`
|
||||
})
|
||||
}
|
||||
|
|
|
@ -172,20 +172,23 @@ async function sendSign (event) {
|
|||
})
|
||||
const hash = web3Home.utils.sha3(msg)
|
||||
const publicKey = utils.recoverPublicKey(hash, { r: tx.r, s: tx.s, v: tx.v })
|
||||
channel.sendToQueue(signQueue.queue, Buffer.from(JSON.stringify({
|
||||
const msgToQueue = JSON.stringify({
|
||||
recipient: publicKeyToAddress({
|
||||
x: publicKey.substr(4, 64),
|
||||
y: publicKey.substr(68, 64)
|
||||
}),
|
||||
value: event.returnValues.value.toNumber(),
|
||||
value: (new BN(event.returnValues.value)).dividedBy(10 ** 18).toFixed(8, 3),
|
||||
epoch,
|
||||
nonce: foreignNonce[epoch],
|
||||
threshold: (await bridge.methods.getThreshold(epoch).call()).toNumber(),
|
||||
parties: (await bridge.methods.getParties(epoch).call()).toNumber()
|
||||
})), {
|
||||
})
|
||||
|
||||
channel.sendToQueue(signQueue.queue, Buffer.from(msgToQueue), {
|
||||
persistent: true
|
||||
})
|
||||
console.log('Sent new sign event')
|
||||
console.log(msgToQueue)
|
||||
|
||||
redisTx.incr(`foreignNonce${epoch}`)
|
||||
foreignNonce[epoch]++
|
||||
|
|
|
@ -213,6 +213,7 @@ function homeSendQuery (query) {
|
|||
chainId: parseInt(HOME_CHAIN_ID)
|
||||
}
|
||||
tx.gas = Math.min(Math.ceil(await query.estimateGas(tx) * 1.5), 6721975)
|
||||
console.log(tx)
|
||||
const signedTx = await homeWeb3.eth.accounts.signTransaction(tx, VALIDATOR_PRIVATE_KEY)
|
||||
|
||||
return homeWeb3.eth.sendSignedTransaction(signedTx.rawTransaction)
|
||||
|
@ -333,8 +334,8 @@ async function transfer (req, res) {
|
|||
console.log('Transfer start')
|
||||
const { hash, to, value } = req.body
|
||||
if (homeWeb3.utils.isAddress(to)) {
|
||||
console.log('Calling transfer')
|
||||
const query = bridge.methods.transfer(hash, to, value)
|
||||
console.log(`Calling transfer to ${to}, ${value} tokens`)
|
||||
const query = bridge.methods.transfer(hash, to, '0x'+(new BN(value).toString(16)))
|
||||
await homeSendQuery(query)
|
||||
} else {
|
||||
// return funds ?
|
||||
|
|
|
@ -10,5 +10,5 @@ const token = new web3.eth.Contract(abiToken, HOME_TOKEN_ADDRESS)
|
|||
const address = process.argv[2]
|
||||
|
||||
token.methods.balanceOf(address).call()
|
||||
.then(x => console.log(x.toNumber()))
|
||||
.then(x => console.log(x.toString()))
|
||||
.catch(() => console.log(0))
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
HOME_RPC_URL=http://ganache_home:8545
|
||||
HOME_BRIDGE_ADDRESS=0x94b40CC641Ed7db241A1f04C8896ba6f6cC36b85
|
||||
|
||||
HOME_CHAIN_ID=44
|
||||
HOME_TOKEN_ADDRESS=0x44c158FE850821ae69DaF37AADF5c539e9d0025B
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
"name": "ethereum-send",
|
||||
"version": "0.0.1",
|
||||
"dependencies": {
|
||||
"bignumber.js": "9.0.0",
|
||||
"web3": "1.0.0-beta.55"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
const Web3 = require('web3')
|
||||
const BN = require('bignumber.js')
|
||||
|
||||
const { HOME_RPC_URL, HOME_BRIDGE_ADDRESS, HOME_CHAIN_ID, HOME_PRIVATE_KEY, HOME_TOKEN_ADDRESS } = process.env
|
||||
|
||||
|
@ -7,27 +8,57 @@ const abiToken = require('./IERC20').abi
|
|||
const web3 = new Web3(HOME_RPC_URL, null, { transactionConfirmationBlocks: 1 })
|
||||
const token = new web3.eth.Contract(abiToken, HOME_TOKEN_ADDRESS)
|
||||
|
||||
const amount = parseInt(process.argv[2])
|
||||
|
||||
const deployAddress = web3.eth.accounts.privateKeyToAccount(`0x${HOME_PRIVATE_KEY}`).address
|
||||
const sender = web3.eth.accounts.privateKeyToAccount(`0x${HOME_PRIVATE_KEY}`).address
|
||||
|
||||
async function main () {
|
||||
console.log(`Transfer from ${deployAddress} to ${HOME_BRIDGE_ADDRESS}, ${amount} tokens`)
|
||||
|
||||
const query = token.methods.transfer(HOME_BRIDGE_ADDRESS, amount)
|
||||
const encodedABI = query.encodeABI()
|
||||
const tx = {
|
||||
data: encodedABI,
|
||||
from: deployAddress,
|
||||
to: HOME_TOKEN_ADDRESS,
|
||||
nonce: await web3.eth.getTransactionCount(deployAddress),
|
||||
chainId: parseInt(HOME_CHAIN_ID)
|
||||
let to = process.argv[2]
|
||||
|
||||
if (to == "bridge") {
|
||||
to = HOME_BRIDGE_ADDRESS
|
||||
}
|
||||
|
||||
const amount = parseInt(process.argv[3])
|
||||
let coins = process.argv[4]
|
||||
|
||||
if (amount != 0) {
|
||||
console.log(`Transfer from ${sender} to ${to}, ${amount} tokens`)
|
||||
|
||||
const query = token.methods.transfer(to, '0x'+(new BN(amount).toString(16)))
|
||||
const encodedABI = query.encodeABI()
|
||||
const tx = {
|
||||
data: encodedABI,
|
||||
from: sender,
|
||||
to: HOME_TOKEN_ADDRESS,
|
||||
nonce: await web3.eth.getTransactionCount(sender),
|
||||
chainId: parseInt(HOME_CHAIN_ID)
|
||||
}
|
||||
tx.gas = Math.min(Math.ceil(await query.estimateGas(tx) * 1.5), 6721975)
|
||||
let signedTx = await web3.eth.accounts.signTransaction(tx, HOME_PRIVATE_KEY)
|
||||
|
||||
let receipt = await web3.eth.sendSignedTransaction(signedTx.rawTransaction)
|
||||
console.log('txHash: ' + receipt.transactionHash)
|
||||
}
|
||||
|
||||
if (coins) {
|
||||
coins = parseFloat(coins)
|
||||
console.log(`Transfer from ${sender} to ${to}, ${coins} coins`)
|
||||
|
||||
const tx_coins = {
|
||||
data: '0x',
|
||||
from: sender,
|
||||
to: to,
|
||||
nonce: await web3.eth.getTransactionCount(sender),
|
||||
chainId: parseInt(HOME_CHAIN_ID),
|
||||
value: web3.utils.toWei(new BN(coins).toString(), 'ether'),
|
||||
gas: 21000
|
||||
}
|
||||
signedTx = await web3.eth.accounts.signTransaction(tx_coins, HOME_PRIVATE_KEY)
|
||||
|
||||
receipt = await web3.eth.sendSignedTransaction(signedTx.rawTransaction)
|
||||
console.log('txHash: ' + receipt.transactionHash)
|
||||
}
|
||||
tx.gas = Math.min(Math.ceil(await query.estimateGas(tx) * 1.5), 6721975)
|
||||
const signedTx = await web3.eth.accounts.signTransaction(tx, HOME_PRIVATE_KEY)
|
||||
|
||||
const receipt = await web3.eth.sendSignedTransaction(signedTx.rawTransaction)
|
||||
console.log(receipt.transactionHash)
|
||||
}
|
||||
|
||||
main()
|
||||
|
|
Loading…
Reference in New Issue