Skip to content

Commit

Permalink
Merge branch 'dev-alessandro'
Browse files Browse the repository at this point in the history
  • Loading branch information
allemanfredi committed Dec 10, 2020
2 parents 9cffabb + 2c37259 commit 826a03f
Show file tree
Hide file tree
Showing 32 changed files with 543 additions and 192 deletions.
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"packages": [
"packages/*"
],
"version": "0.7.1"
"version": "0.8.0"
}
8 changes: 4 additions & 4 deletions packages/ptokens-deposit-address/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ptokens-deposit-address",
"version": "0.7.1",
"version": "0.8.0",
"description": "repo holding the code related to deposit addresses",
"repository": "https://github.com/provable-things/ptokens.js/tree/master/packages/ptokens-deposit-address",
"main": "dist/ptokens-deposit-address.cjs.js",
Expand Down Expand Up @@ -32,9 +32,9 @@
"bitcoinjs-lib": "^5.1.6",
"chai": "^4.2.0",
"eosjs": "^20.0.3",
"ptokens-node": "^0.7.1",
"ptokens-providers": "^0.7.1",
"ptokens-utils": "^0.7.1",
"ptokens-node": "^0.8.0",
"ptokens-providers": "^0.8.0",
"ptokens-utils": "^0.8.0",
"web3": "^1.2.2"
},
"devDependencies": {
Expand Down
52 changes: 28 additions & 24 deletions packages/ptokens-deposit-address/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ export class DepositAddress {

// NOTE: eos account name are utf-8 encoded
const hostAddressBuf =
this.hostBlockchain === constants.blockchains.Eosio
this.hostBlockchain === constants.blockchains.Eosio ||
this.hostBlockchain === constants.blockchains.Telos
? Buffer.from(this.hostAddress, 'utf-8')
: Buffer.from(utils.eth.removeHexPrefix(this.hostAddress), 'hex')

Expand Down Expand Up @@ -185,35 +186,38 @@ export class DepositAddress {
this.hostBlockchain
)

const nativeTxId = await utils[
shortNativeBlockchain
].monitorUtxoByAddress(
this.nativeNetwork,
this.value,
promiEvent.eventEmitter,
POLLING_TIME,
'nativeTxBroadcasted',
'nativeTxConfirmed',
confirmations[shortNativeBlockchain]
)
// prettier-ignore
const nativeTxId = await utils[shortNativeBlockchain]
.monitorUtxoByAddress(
this.nativeNetwork,
this.value,
promiEvent.eventEmitter,
POLLING_TIME,
'nativeTxBroadcasted',
'nativeTxConfirmed',
confirmations[shortNativeBlockchain]
)

const broadcastedHostTxReport = await this.node.monitorIncomingTransaction(
nativeTxId,
promiEvent.eventEmitter
)

const hostTxReceipt = await utils[
shortHostBlockchain
].waitForTransactionConfirmation(
this.hostApi,
broadcastedHostTxReport.broadcast_tx_hash,
HOST_NODE_POLLING_TIME_INTERVAL
)

promiEvent.eventEmitter.emit(
hostBlockchainEvents[this.hostBlockchain],
hostTxReceipt
)
// prettier-ignore
const hostTxReceipt = await utils[shortHostBlockchain]
.waitForTransactionConfirmation(
this.hostApi,
broadcastedHostTxReport.broadcast_tx_hash,
HOST_NODE_POLLING_TIME_INTERVAL
)

if (this.hostBlockchain !== utils.constants.blockchains.Telos) {
// NOTE: 'onEosTxConfirmed & onEthTxConfirmed' will be removed in version >= 1.0.0
promiEvent.eventEmitter.emit(
hostBlockchainEvents[this.hostBlockchain],
hostTxReceipt
)
}
promiEvent.eventEmitter.emit('hostTxConfirmed', hostTxReceipt)

promiEvent.resolve({
Expand Down
8 changes: 4 additions & 4 deletions packages/ptokens-node-selector/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ptokens-node-selector",
"version": "0.7.1",
"version": "0.8.0",
"description": "repo holding the code for selecting validator nodes",
"repository": "https://github.com/provable-things/ptokens.js/tree/master/packages/ptokens-node-selector",
"main": "dist/ptokens-node-selector.cjs.js",
Expand All @@ -21,9 +21,9 @@
"@types/node": "^12.6.1",
"axios": "^0.19.0",
"chai": "^4.2.0",
"ptokens-node": "^0.7.1",
"ptokens-utils": "^0.7.1",
"ptokens-providers": "^0.7.1"
"ptokens-node": "^0.8.0",
"ptokens-providers": "^0.8.0",
"ptokens-utils": "^0.8.0"
},
"devDependencies": {
"dtslint": "0.4.2",
Expand Down
6 changes: 3 additions & 3 deletions packages/ptokens-node/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ptokens-node",
"version": "0.7.1",
"version": "0.8.0",
"description": "repo holding the code for interacting with a Node",
"repository": "https://github.com/provable-things/ptokens.js/tree/master/packages/ptokens-node",
"main": "dist/ptokens-node.cjs.js",
Expand Down Expand Up @@ -31,8 +31,8 @@
"eventemitter3": "^4.0.0",
"jsonrpc-lite": "^2.2.0",
"light-async-polling": "^1.0.2",
"ptokens-providers": "^0.7.1",
"ptokens-utils": "^0.7.1",
"ptokens-providers": "^0.8.0",
"ptokens-utils": "^0.8.0",
"uuid": "^8.3.1",
"web3-core-promievent": "^1.2.5-rc.0"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/ptokens-node/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { helpers } from 'ptokens-utils'
import jsonrpc from 'jsonrpc-lite'
import { v4 as uuidv4 } from 'uuid'

const NODE_POLLING_TIME = 200
const NODE_POLLING_TIME = 2000
const REPORT_LIMIT = 100

export class Node {
Expand Down
12 changes: 6 additions & 6 deletions packages/ptokens-pbtc/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ptokens-pbtc",
"version": "0.7.1",
"version": "0.8.0",
"description": "repo holding the code for interacting with pBTC",
"repository": "https://github.com/provable-things/ptokens.js/tree/master/packages/ptokens-pbtc",
"main": "dist/ptokens-pbtc.cjs.js",
Expand Down Expand Up @@ -31,11 +31,11 @@
"bitcoinjs-lib": "^5.1.6",
"chai": "^4.2.0",
"eosjs": "^20.0.0",
"ptokens-deposit-address": "^0.7.1",
"ptokens-node": "^0.7.1",
"ptokens-node-selector": "^0.7.1",
"ptokens-providers": "^0.7.1",
"ptokens-utils": "^0.7.1",
"ptokens-deposit-address": "^0.8.0",
"ptokens-node": "^0.8.0",
"ptokens-node-selector": "^0.8.0",
"ptokens-providers": "^0.8.0",
"ptokens-utils": "^0.8.0",
"web3": "^1.2.2",
"web3-core-promievent": "^1.2.1",
"web3-utils": "^1.2.4"
Expand Down
26 changes: 13 additions & 13 deletions packages/ptokens-pbtc/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { NodeSelector } from 'ptokens-node-selector'
import { constants, eth, eos, btc, helpers, redeemFrom } from 'ptokens-utils'
import { DepositAddress } from 'ptokens-deposit-address'
import Web3Utils from 'web3-utils'
import BigNumber from 'bignumber.js'

const MINIMUM_BTC_REDEEMABLE = 0.00005

Expand Down Expand Up @@ -113,7 +112,7 @@ export class pBTC extends NodeSelector {
}

/**
* @param {Number} _amount
* @param {Number|BigNumber|String} _amount
* @param {String} _btcAddress
* @param {RedeemOptions} _options
*/
Expand All @@ -138,7 +137,6 @@ export class pBTC extends NodeSelector {
if (!this.selectedNode) await this.select()

// prettier-ignore
const decimals = this.hostBlockchain === constants.blockchains.Ethereum ? 18 : 8
const contractAddress = await this._getContractAddress()

const { redeemFromEthereum, redeemFromEosio } = redeemFrom
Expand All @@ -154,31 +152,33 @@ export class pBTC extends NodeSelector {
contractAddress,
value: 0
},
[
eth.onChainFormat(new BigNumber(_amount), decimals).toFixed(),
_btcAddress
],
[_amount, _btcAddress],
promiEvent,
'nativeTxBroadcasted'
'hostTxBroadcasted'
)
// NOTE: 'onEthTxConfirmed' will be removed in version >= 1.0.0
promiEvent.eventEmitter.emit('onEthTxConfirmed', ethTxReceipt)
promiEvent.eventEmitter.emit('hostTxConfirmed', ethTxReceipt)
hostTxHash = ethTxReceipt.transactionHash
}

if (this.hostBlockchain === constants.blockchains.Eosio) {
if (
this.hostBlockchain === constants.blockchains.Eosio ||
this.hostBlockchain === constants.blockchains.Telos
) {
const eosTxReceipt = await redeemFromEosio(
this.hostApi,
_amount,
_btcAddress,
decimals,
8,
contractAddress,
constants.pTokens.pBTC
)

// NOTE: 'onEosTxConfirmed' will be removed in version >= 1.0.0
promiEvent.eventEmitter.emit('onEosTxConfirmed', eosTxReceipt)
if (this.hostBlockchain === constants.blockchains.Eosio) {
// NOTE: 'onEosTxConfirmed' will be removed in version >= 1.0.0
promiEvent.eventEmitter.emit('onEosTxConfirmed', eosTxReceipt)
}
promiEvent.eventEmitter.emit('hostTxConfirmed', eosTxReceipt)
hostTxHash = eosTxReceipt.transaction_id
}
Expand All @@ -200,7 +200,7 @@ export class pBTC extends NodeSelector {
promiEvent.eventEmitter.emit('nativeTxConfirmed', broadcastedBtcTxReceipt)

promiEvent.resolve({
amount: _amount.toFixed(decimals),
amount: _amount,
hostTx: hostTxHash,
nativeTx: broadcastedBtcTxReport.broadcast_tx_hash,
to: _btcAddress
Expand Down
12 changes: 6 additions & 6 deletions packages/ptokens-pbtc/tests/ptokens-pbtc-on-eth.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { pBTC } from '../src/index'
import { expect } from 'chai'
import { sendBitcoin } from './utils'
import { constants } from 'ptokens-utils'
import BigNumber from 'bignumber.js'
// import qrcode from 'qrcode-terminal'

const ETH_TESTING_ADDRESS = ''
Expand Down Expand Up @@ -110,7 +111,9 @@ test('Should monitor an issuing of 0.00050100 pBTC on Ethereum', async () => {
})

test('Should redeem 0.0005 pBTC on Ethereum', async () => {
const amountToRedeem = 0.0005
const amountToRedeem = BigNumber(0.0005)
.multipliedBy(10 ** 18)
.toFixed()
let ethTxBroadcasted = 0
let ethTxIsConfirmed = 0
let nodeHasReceivedTx = 0
Expand All @@ -123,10 +126,7 @@ test('Should redeem 0.0005 pBTC on Ethereum', async () => {
gasPrice: 75e9,
gas: 200000
})
.once('onEthTxBroadcasted', () => {
ethTxBroadcasted += 1
})
.once('nativeTxBroadcasted', () => {
.once('hostTxBroadcasted', () => {
ethTxBroadcasted += 1
})
.once('onEthTxConfirmed', () => {
Expand Down Expand Up @@ -158,7 +158,7 @@ test('Should redeem 0.0005 pBTC on Ethereum', async () => {
})
await start()

expect(ethTxBroadcasted).to.equal(2)
expect(ethTxBroadcasted).to.equal(1)
expect(ethTxIsConfirmed).to.equal(2)
expect(nodeHasReceivedTx).to.equal(2)
expect(nodeHasBroadcastedTx).to.equal(2)
Expand Down
Loading

0 comments on commit 826a03f

Please sign in to comment.