diff --git a/packages/ptokens-pbep20/README.md b/packages/ptokens-pbep20/README.md new file mode 100644 index 00000000..7c77af17 --- /dev/null +++ b/packages/ptokens-pbep20/README.md @@ -0,0 +1,54 @@ +# ptokens-pbep20 + +It allows to easily convert any BEP20 tokens on the Binance Smart Chain blockchain into their pTokenized equivalents on the another blockchain. + +  + +*** + +  + +### Installation: + +``` +npm install ptokens-pbep20 +``` + +  + +*** + +  + +### Usage: + +```js +import { pBEP20 } from 'ptokens-pbep20' +import { HttpProvider } from 'ptokens-providers' +import { Node } from 'ptokens-node' + +const pbep20 = new pBEP20({ + blockchain: 'ETH', + network: 'testnet', // 'testnet' or 'mainnet', default 'testnet' + + // if you want to be more detailed + hostBlockchain: 'ETH', + hostNetwork: 'mainnet', + nativeBlockchain: 'BSC' + nativeNetwork: 'mainnet' + + ethPrivateKey: 'Eth private key', + ethProvider: 'Eth provider', // or instance of Web3 provider + defaultNode: new Node({ + pToken: 'OCP', + blockchain: 'ETH', + provider: new HttpProvider( + 'node endpoint', + { + 'Access-Control-Allow-Origin': '*', + ... + } + ) + }) +}) +``` \ No newline at end of file diff --git a/packages/ptokens-pbep20/jest.config.js b/packages/ptokens-pbep20/jest.config.js new file mode 100644 index 00000000..08880dad --- /dev/null +++ b/packages/ptokens-pbep20/jest.config.js @@ -0,0 +1,3 @@ +const jestConfig = require('../../jest.config') + +module.exports = jestConfig() diff --git a/packages/ptokens-pbep20/package.json b/packages/ptokens-pbep20/package.json new file mode 100644 index 00000000..49183e78 --- /dev/null +++ b/packages/ptokens-pbep20/package.json @@ -0,0 +1,46 @@ +{ + "name": "ptokens-pbep20", + "version": "0.10.0", + "description": "repo holding the code for interacting with a BEP20 token", + "repository": "https://github.com/provable-things/ptokens.js/tree/master/packages/ptokens-pbep20", + "main": "dist/ptokens-pbep20.cjs.js", + "module": "dist/ptokens-pbep20.esm.js", + "browser": "dist/ptokens-pbep20.umd.js", + "types": "types/index.d.ts", + "scripts": { + "build": "rollup -c", + "dev": "rollup -c -w", + "test": "jest --ci --forceExit --detectOpenHandles", + "lint": "npx eslint ./src --fix && npx eslint ./tests --fix", + "dtslint": "dtslint types --onlyTestTsNext" + }, + "keywords": [ + "ptokens", + "javaScript", + "ethereum", + "eos", + "pnetwork" + ], + "author": "alle.manfredi@gmail.com @provable-things", + "license": "LGPL-3.0", + "dependencies": { + "@babel/runtime": "^7.3.1", + "@types/node": "^12.6.1", + "bignumber.js": "^9.0.0", + "chai": "^4.2.0", + "ptokens-node": "^0.10.0", + "ptokens-node-selector": "^0.10.0", + "ptokens-utils": "^0.10.0", + "web3": "^1.2.2", + "web3-core-promievent": "^1.2.1", + "web3-utils": "^1.2.4" + }, + "devDependencies": { + "dtslint": "0.4.2", + "jest": "^24.8.0" + }, + "files": [ + "dist", + "types/index.d.ts" + ] +} diff --git a/packages/ptokens-pbep20/rollup.config.js b/packages/ptokens-pbep20/rollup.config.js new file mode 100644 index 00000000..b5c7ead1 --- /dev/null +++ b/packages/ptokens-pbep20/rollup.config.js @@ -0,0 +1,8 @@ +import pkg from './package.json' +import rollupConfig from '../../rollup.config' + +export default rollupConfig('pBEP20', pkg.name, { + 'ptokens-node-selector': 'ptokens-node-selector', + 'ptokens-node': 'ptokens-node', + 'ptokens-utils': 'ptokens-utils' +}) diff --git a/packages/ptokens-pbep20/src/index.js b/packages/ptokens-pbep20/src/index.js new file mode 100644 index 00000000..14f0a06e --- /dev/null +++ b/packages/ptokens-pbep20/src/index.js @@ -0,0 +1,209 @@ +import Web3 from 'web3' +import Web3PromiEvent from 'web3-core-promievent' +import { NodeSelector } from 'ptokens-node-selector' +import { abi, constants, eth, helpers, redeemFrom } from 'ptokens-utils' +import BigNumber from 'bignumber.js' +import Web3Utils from 'web3-utils' +import minimumAmounts from './minimum-amounts' + +export class pBEP20 extends NodeSelector { + constructor(_configs) { + const { hostBlockchain, hostNetwork, nativeBlockchain, nativeNetwork } = helpers.parseParams( + _configs, + constants.blockchains.BinanceSmartChain + ) + + super({ + pToken: _configs.pToken, + hostBlockchain, + hostNetwork, + nativeBlockchain, + nativeNetwork, + defaultNode: _configs.defaultNode + }) + + const { bscPrivateKey, bscProvider, ethPrivateKey, ethProvider } = _configs + + if (bscProvider) this.web3 = new Web3(bscProvider) + if (bscPrivateKey) { + const account = this.web3.eth.accounts.privateKeyToAccount(eth.addHexPrefix(bscPrivateKey)) + this.web3.eth.defaultAccount = account.address + this.bscPrivateKey = eth.addHexPrefix(bscPrivateKey) + } else { + this.bscPrivateKey = null + } + + if (ethProvider) this.hostApi = new Web3(ethProvider) + if (ethPrivateKey) { + const account = this.hostApi.eth.accounts.privateKeyToAccount(eth.addHexPrefix(ethPrivateKey)) + this.hostApi.eth.defaultAccount = account.address + this.hostPrivateKey = eth.addHexPrefix(ethPrivateKey) + } else { + this.hostPrivateKey = null + } + } + /** + * @param {String|BigNumber|BN} _amount in wei + * @param {String} _hostAccount + * @param {IssueOptions} _options + */ + issue(_amount, _hostAccount, _options = {}) { + const promiEvent = Web3PromiEvent() + const start = async () => { + try { + const { gas, gasPrice } = _options + const { blockchains } = constants + await this._loadData() + + const minimumAmount = minimumAmounts[this.nativeContractAddress.toLowerCase()].issue + if (BigNumber(_amount).isLessThan(minimumAmount)) { + promiEvent.reject(`Impossible to issue less than ${minimumAmount}`) + return + } + + if (this.hostBlockchain === blockchains.Ethereum && !Web3Utils.isAddress(_hostAccount)) { + promiEvent.reject('Invalid host account') + return + } + + if (!this.selectedNode) await this.select() + + let bscTxHash = null + const waitForEthTransaction = () => + new Promise((_resolve, _reject) => { + eth[this.bscPrivateKey ? 'sendSignedMethodTx' : 'makeContractSend']( + this.web3, + 'pegIn', + { + privateKey: this.bscPrivateKey, + abi: abi.pERC20Vault, + gas, + gasPrice, + contractAddress: eth.addHexPrefix(this.nativeVaultAddress), + value: 0 + }, + [_amount, this.nativeContractAddress, _hostAccount] + ) + .once('transactionHash', _hash => { + bscTxHash = _hash + promiEvent.eventEmitter.emit('nativeTxBroadcasted', bscTxHash) + }) + .once('receipt', _resolve) + .once('error', _reject) + }) + const ethTxReceipt = await waitForEthTransaction() + promiEvent.eventEmitter.emit('nativeTxConfirmed', ethTxReceipt) + + const incomingTxReport = await this.selectedNode.monitorIncomingTransaction(bscTxHash, promiEvent.eventEmitter) + + let hostTxReceipt + if (this.hostBlockchain === blockchains.Ethereum) + hostTxReceipt = await eth.waitForTransactionConfirmation(this.hostApi, incomingTxReport.broadcast_tx_hash) + + promiEvent.eventEmitter.emit('hostTxConfirmed', hostTxReceipt) + promiEvent.resolve({ + to: _hostAccount, + nativeTx: bscTxHash, + hostTx: incomingTxReport.broadcast_tx_hash, + amount: BigNumber(_amount).toFixed() + }) + } catch (_err) { + promiEvent.reject(_err) + } + } + + start() + return promiEvent.eventEmitter + } + + /** + * + * @param {string|number} _amount + * @param {string} _nativeAccount + * @param {Options} _options + */ + redeem(_amount, _nativeAccount, _options = {}) { + const promiEvent = Web3PromiEvent() + + const start = async () => { + try { + const { gas, gasPrice } = _options + const { blockchains } = constants + + await this._loadData() + + const minimumAmount = minimumAmounts[this.nativeContractAddress.toLowerCase()].redeem[this.hostBlockchain] + if (BigNumber(_amount).isLessThan(minimumAmount)) { + promiEvent.reject(`Impossible to redeem less than ${minimumAmount}`) + return + } + + if (this.nativeBlockchain === blockchains.Ethereum && !Web3Utils.isAddress(_nativeAccount)) { + promiEvent.reject('Invalid native account') + return + } + + if (!this.selectedNode) await this.select() + + const { redeemFromEvmCompatible } = redeemFrom + + let hostTxHash + if (this.hostBlockchain === blockchains.Ethereum) { + const hostTxReceipt = await redeemFromEvmCompatible( + this.hostApi, + { + privateKey: this.hostPrivateKey, + gas, + gasPrice, + contractAddress: this.hostContractAddress, + value: 0 + }, + [_amount, _nativeAccount], + promiEvent, + 'hostTxBroadcasted' + ) + + promiEvent.eventEmitter.emit('hostTxConfirmed', hostTxReceipt) + hostTxHash = hostTxReceipt.transactionHash + } + + const incomingTxReport = await this.selectedNode.monitorIncomingTransaction(hostTxHash, promiEvent.eventEmitter) + const nativeTxReceipt = await eth.waitForTransactionConfirmation( + this.hostApi, + incomingTxReport.broadcast_tx_hash + ) + promiEvent.eventEmitter.emit('nativeTxConfirmed', nativeTxReceipt) + + promiEvent.resolve({ + to: _nativeAccount, + nativeTx: nativeTxReceipt.transactionHash, + hostTx: hostTxHash, + amount: BigNumber(_amount).toFixed() + }) + } catch (_err) { + promiEvent.reject(_err) + } + } + + start() + return promiEvent.eventEmitter + } + + async _loadData() { + try { + if (!this.selectedNode) await this.select() + if (!this.nativeContractAddress || !this.hostContractAddress) { + const { + native_smart_contract_address, + host_smart_contract_address, + native_vault_address + } = await this.selectedNode.getInfo() + this.nativeContractAddress = eth.addHexPrefix(native_smart_contract_address) + this.hostContractAddress = eth.addHexPrefix(host_smart_contract_address) + this.nativeVaultAddress = native_vault_address ? eth.addHexPrefix(native_vault_address) : null + } + } catch (_err) { + throw new Error(`Error during loading data: ${_err.message}`) + } + } +} diff --git a/packages/ptokens-pbep20/src/minimum-amounts.js b/packages/ptokens-pbep20/src/minimum-amounts.js new file mode 100644 index 00000000..da0aacf2 --- /dev/null +++ b/packages/ptokens-pbep20/src/minimum-amounts.js @@ -0,0 +1,9 @@ +import { constants } from 'ptokens-utils' +export default { + [constants.tokens['binance-smart-chain'].mainnet.OCP]: { + issue: 1000000000, + redeem: { + [constants.blockchains.Ethereum]: 0.000000001 + } + } +} diff --git a/packages/ptokens-pbep20/tests/ptokens-ocp-on-eth.test.js b/packages/ptokens-pbep20/tests/ptokens-ocp-on-eth.test.js new file mode 100644 index 00000000..9cec94bb --- /dev/null +++ b/packages/ptokens-pbep20/tests/ptokens-ocp-on-eth.test.js @@ -0,0 +1,156 @@ +import { pBEP20 } from '../src/index' +import { expect } from 'chai' +import { constants, eth } from 'ptokens-utils' +import BigNumber from 'bignumber.js' +import Web3 from 'web3' + +const ETH_TESTING_ADDRESS = '' +const ETH_TESTING_PRIVATE_KEY = '' +const ETH_WEB3_PROVIDER = '' +const BSC_TESTING_ADDRESS = '' +const BSC_TESTING_PRIVATE_KEY = '' +const BSC_WEB3_PROVIDER = '' + +jest.setTimeout(3000000) + +let ocp = null +beforeEach(() => { + ocp = new pBEP20({ + blockchain: constants.blockchains.Ethereum, + network: constants.networks.Mainnet, + ethPrivateKey: ETH_TESTING_PRIVATE_KEY, + ethProvider: ETH_WEB3_PROVIDER, + bscPrivateKey: BSC_TESTING_PRIVATE_KEY, + bscProvider: BSC_WEB3_PROVIDER, + pToken: constants.pTokens.OCP + }) +}) + +test('Should not issue less than 1000000000 OCP', async () => { + const amountToIssue = BigNumber('900000000') + try { + await ocp.issue(amountToIssue, ETH_TESTING_ADDRESS) + } catch (_err) { + expect(_err).to.be.equal('Impossible to issue less than 1000000000') + } +}) + +test('Should issue 0.00002 OCP using ETH', async () => { + const amountToIssue = BigNumber('20000000000000') + let bscTxBroadcasted = 2 + let bscTxIsConfirmed = false + let nodeHasReceivedTx = false + let nodeHasBroadcastedTx = false + let ethTxIsConfirmed = false + + await ocp.select() + const { native_vault_address } = await ocp.selectedNode.getInfo() + + const web3 = new Web3(BSC_WEB3_PROVIDER) + web3.eth.defaultAccount = ETH_TESTING_ADDRESS + await eth.sendSignedMethodTx( + web3, + 'approve', + { + privateKey: BSC_TESTING_PRIVATE_KEY, + abi: [ + { + constant: false, + inputs: [ + { + name: '_spender', + type: 'address' + }, + { + name: '_value', + type: 'uint256' + } + ], + name: 'approve', + outputs: [ + { + name: '', + type: 'bool' + } + ], + payable: false, + stateMutability: 'nonpayable', + type: 'function' + } + ], + gas: 200000, + gasPrice: 5e9, + contractAddress: constants.tokens['binance-smart-chain'].mainnet.OCP, + value: 0 + }, + [eth.addHexPrefix(native_vault_address), BigNumber('20000000000000')] + ) + + const start = () => + new Promise(resolve => { + ocp + .issue(amountToIssue, ETH_TESTING_ADDRESS, { + gasPrice: 5e9, + gas: 200000 + }) + .once('nativeTxBroadcasted', () => { + bscTxBroadcasted = true + }) + .once('nativeTxConfirmed', () => { + bscTxIsConfirmed = true + }) + .once('nodeReceivedTx', () => { + nodeHasReceivedTx = true + }) + .once('nodeBroadcastedTx', () => { + nodeHasBroadcastedTx = true + }) + .once('hostTxConfirmed', () => { + ethTxIsConfirmed = true + }) + .then(() => resolve()) + }) + await start() + expect(bscTxBroadcasted).to.equal(true) + expect(bscTxIsConfirmed).to.equal(true) + expect(nodeHasReceivedTx).to.equal(true) + expect(nodeHasBroadcastedTx).to.equal(true) + expect(ethTxIsConfirmed).to.equal(true) +}) + +test('Should redeem 0.00002 OCP from BSC', async () => { + const amountToRedeem = BigNumber('20000000000000') + let ethTxIsBroadcasted = false + let ethTxIsConfirmed = false + let nodeHasReceivedTx = false + let nodeHasBroadcastedTx = false + let bscTxIsConfirmed = false + const start = () => + new Promise((resolve, reject) => { + ocp + .redeem(amountToRedeem, BSC_TESTING_ADDRESS, { gasPrice: 75e9, gas: 200000 }) + .once('hostTxBroadcasted', () => { + ethTxIsBroadcasted = true + }) + .once('hostTxConfirmed', () => { + ethTxIsConfirmed = true + }) + .once('nodeReceivedTx', () => { + nodeHasReceivedTx = true + }) + .once('nodeBroadcastedTx', () => { + nodeHasBroadcastedTx = true + }) + .once('nativeTxConfirmed', () => { + bscTxIsConfirmed = true + }) + .then(() => resolve()) + .catch(_err => reject(_err)) + }) + await start() + expect(ethTxIsBroadcasted).to.equal(true) + expect(ethTxIsConfirmed).to.equal(true) + expect(nodeHasReceivedTx).to.equal(true) + expect(nodeHasBroadcastedTx).to.equal(true) + expect(bscTxIsConfirmed).to.equal(true) +}) diff --git a/packages/ptokens-pbep20/types/index.d.ts b/packages/ptokens-pbep20/types/index.d.ts new file mode 100644 index 00000000..33519d11 --- /dev/null +++ b/packages/ptokens-pbep20/types/index.d.ts @@ -0,0 +1,62 @@ +import { Node, Report } from 'ptokens-node' +import { TransactionReceipt, PromiEvent } from 'web3-core' +import Web3 from 'web3' +import { NodeSelector } from 'ptokens-node-selector' +import { BigNumber } from 'bignumber.js' +import BN = require('bn.js') + +export interface pBEP20Configs { + network?: string, + hostNetwork?: string, + blockchain?: string, + hostBlockchain?: string, + nativeNetwork?: string, + nativeBlockchain?: string, + ethPrivateKey?: string, + ethProvider?: string | object, + bscPrivateKey?: string, + bscProvider?: string | object, + defaultNode?: Node, + pToken: string +} + +export interface IssueOptions { + gas: number, + gasPrice: number | string | BigNumber, +} + +export interface RedeemOptions { + gasPrice: number | string | BigNumber, + gas: string | number +} + +export class pBEP20 extends NodeSelector { + constructor(configs: pBEP20Configs) + + nodeSelector: NodeSelector + + decimals: string | null + + nativeContractAddress: string | null + + hostContractAddress: string | null + + nativeVaultAddress: string | null + + hostPrivatekey?: string | null + + web3: Web3 + + hostApi?: Web3 + + issue(_amount: string | BigNumber | BN, _hostAddress: string, _options: IssueOptions): PromiEvent + + redeem(_amount: number | string, _nativeAddress: string, _options: RedeemOptions): PromiEvent +} + +export interface Result { + amount: number, + nativeTx: string, + hostTx: string, + to: string, +} diff --git a/packages/ptokens-pbep20/types/tests/ptokens-pbep20-test.ts b/packages/ptokens-pbep20/types/tests/ptokens-pbep20-test.ts new file mode 100644 index 00000000..3abbe09c --- /dev/null +++ b/packages/ptokens-pbep20/types/tests/ptokens-pbep20-test.ts @@ -0,0 +1,19 @@ +import { pBEP20 } from 'ptokens-pbep20' + +const pbep20 = new pBEP20({ + network: 'mainnet', + blockchain: 'eth', + pToken: 'ocp', +}) + +// $ExpectType PromiEvent +pbep20.issue('1000000000000', 'eos account', { + gas: 10, + gasPrice: 10 +}) + +// $ExpectType PromiEvent +pbep20.redeem(0.002, 'eth address', { + gas: 10, + gasPrice: 10 +}) diff --git a/packages/ptokens-pbep20/types/tsconfig.json b/packages/ptokens-pbep20/types/tsconfig.json new file mode 100644 index 00000000..62a8b270 --- /dev/null +++ b/packages/ptokens-pbep20/types/tsconfig.json @@ -0,0 +1,17 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": ["es6", "dom"], + "target": "es6", + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "noEmit": true, + "allowSyntheticDefaultImports": false, + "baseUrl": ".", + "paths": { + "ptokens-pbep20": ["."] + } + } +} diff --git a/packages/ptokens-pbep20/types/tslint.json b/packages/ptokens-pbep20/types/tslint.json new file mode 100644 index 00000000..0435f238 --- /dev/null +++ b/packages/ptokens-pbep20/types/tslint.json @@ -0,0 +1,10 @@ +{ + "extends": "dtslint/dtslint.json", + "rules": { + "semicolon": false, + "no-import-default-of-export-equals": false, + "file-name-casing": [true, "kebab-case"], + "whitespace": false, + "no-unnecessary-class": false + } +} diff --git a/packages/ptokens-utils/src/constants.js b/packages/ptokens-utils/src/constants.js index bdae13b2..2e2db78a 100644 --- a/packages/ptokens-utils/src/constants.js +++ b/packages/ptokens-utils/src/constants.js @@ -59,7 +59,8 @@ import { pUSDT, pUSDC, pRVN, - pOPEN + pOPEN, + OCP } from './helpers/names' import tokens from './helpers/tokens' @@ -142,7 +143,8 @@ const pTokens = { pUSDT, pUSDC, pRVN, - pOPEN + pOPEN, + OCP } export { blockchains, networks, pTokens, tokens } diff --git a/packages/ptokens-utils/src/helpers/maps.js b/packages/ptokens-utils/src/helpers/maps.js index dbfa2155..e85bb1aa 100644 --- a/packages/ptokens-utils/src/helpers/maps.js +++ b/packages/ptokens-utils/src/helpers/maps.js @@ -59,7 +59,8 @@ import { pUSDC, pUSDT, pRVN, - pOPEN + pOPEN, + OCP } from './names' export const blockchainTypes = { @@ -132,7 +133,8 @@ export const pTokenNativeBlockchain = { pusdc: Ethereum, pusdt: Ethereum, prvn: Ravencoin, - popen: Ethereum + popen: Ethereum, + ocp: BinanceSmartChain } export const networkLabels = { @@ -223,5 +225,6 @@ export const pTokensAvailables = [ pUSDT, pUSDC, pRVN, - pOPEN + pOPEN, + OCP ] diff --git a/packages/ptokens-utils/src/helpers/names.js b/packages/ptokens-utils/src/helpers/names.js index 952ab568..87694234 100644 --- a/packages/ptokens-utils/src/helpers/names.js +++ b/packages/ptokens-utils/src/helpers/names.js @@ -62,3 +62,4 @@ export const pUSDC = 'pusdc' export const pUSDT = 'pusdt' export const pRVN = 'prvn' export const pOPEN = 'popen' +export const OCP = 'ocp' diff --git a/packages/ptokens-utils/src/helpers/tokens.js b/packages/ptokens-utils/src/helpers/tokens.js index 743b05c5..3e2e9016 100644 --- a/packages/ptokens-utils/src/helpers/tokens.js +++ b/packages/ptokens-utils/src/helpers/tokens.js @@ -1,4 +1,13 @@ -import { EthereumMainnet, EosioMainnet, Ethereum, Eosio, Telos, TelosMainnet } from './names' +import { + EthereumMainnet, + EosioMainnet, + Ethereum, + Eosio, + Telos, + TelosMainnet, + BinanceSmartChain, + BinanceSmartChainMainnet +} from './names' export default { [Ethereum]: { @@ -33,6 +42,11 @@ export default { OPEN: '0x69e8b9528cabda89fe846c67675b5d73d463a916' } }, + [BinanceSmartChain]: { + [BinanceSmartChainMainnet]: { + OCP: '0x3c70260eee0a2bfc4b375feb810325801f289fbd' + } + }, [Eosio]: { [EosioMainnet]: { EOS: 'eosio.token', diff --git a/packages/ptokens-utils/types/index.d.ts b/packages/ptokens-utils/types/index.d.ts index 6d999d65..bb967628 100644 --- a/packages/ptokens-utils/types/index.d.ts +++ b/packages/ptokens-utils/types/index.d.ts @@ -241,7 +241,8 @@ export interface pTokens { pUSDC: string, pUSDT: string, pRVN: string, - pOPEN: string + pOPEN: string, + OCP: string } export interface EthereumMainnetTokens { @@ -275,6 +276,10 @@ export interface EthereumMainnetTokens { OPEN: string } +export interface BinanceSmartChainMainnetTokens { + OCP: string +} + export interface TelosMainnetTokens { TELOS: string } @@ -296,10 +301,15 @@ export interface EosioTokens { mainnet: EosioMainnetTokens } +export interface BinanceSmartChainTokens { + mainnet: BinanceSmartChainMainnetTokens +} + export interface Tokens { ethereum: EthereumTokens, eosio: EosioTokens, - telos: TelosTokens + telos: TelosTokens, + 'binance-smart-chain': BinanceSmartChainTokens } export interface Constants { @@ -466,7 +476,6 @@ export interface DogeUtils { export const doge: LtcUtils - // ltc export interface RavencoinUtxoList extends Array {} @@ -553,4 +562,4 @@ export interface RvnUtils { waitForTransactionConfirmation(_network: string, _tx: string, _pollingTime: number, _broadcastEventName: string, _confirmationEventName: string): Promise } -export const rvn: RvnUtils \ No newline at end of file +export const rvn: RvnUtils diff --git a/packages/ptokens/package.json b/packages/ptokens/package.json index 9393ccfb..902809ee 100644 --- a/packages/ptokens/package.json +++ b/packages/ptokens/package.json @@ -36,6 +36,7 @@ "ptokens-pdoge": "^0.10.0", "ptokens-peosio-token": "^0.10.0", "ptokens-perc20": "^0.10.0", + "ptokens-pbep20": "^0.10.0", "ptokens-pltc": "^0.10.0", "ptokens-prvn": "^0.10.0", "ptokens-providers": "^0.10.0", diff --git a/packages/ptokens/rollup.config.js b/packages/ptokens/rollup.config.js index 33c50542..cce10452 100644 --- a/packages/ptokens/rollup.config.js +++ b/packages/ptokens/rollup.config.js @@ -5,6 +5,7 @@ export default rollupConfig('pTokens', pkg.name, { 'ptokens-pbtc': 'ptokens-pbtc', 'ptokens-pdoge': 'ptokens-pdoge', 'ptokens-perc20': 'ptokens-perc20', + 'ptokens-pbep20': 'ptokens-pbep20', 'ptokens-peosio-token': 'ptokens-peosio-token', 'ptokens-pltc': 'ptokens-pltc', 'ptokens-prvn': 'ptokens-prvn', diff --git a/packages/ptokens/src/index.js b/packages/ptokens/src/index.js index 2100e298..b041c50b 100644 --- a/packages/ptokens/src/index.js +++ b/packages/ptokens/src/index.js @@ -2,6 +2,7 @@ import { pBTC } from 'ptokens-pbtc' import { pLTC } from 'ptokens-pltc' import { pRVN } from 'ptokens-prvn' import { pERC20 } from 'ptokens-perc20' +import { pBEP20 } from 'ptokens-pbep20' import { pEosioToken } from 'ptokens-peosio-token' import { pDOGE } from 'ptokens-pdoge' import utils from 'ptokens-utils' @@ -12,7 +13,7 @@ class pTokens { * @param {Object} _configs */ constructor(_configs) { - const { pbtc, pltc, prvn, perc20, pdoge, peosioToken } = _configs + const { pbtc, pltc, prvn, perc20, pbep20, pdoge, peosioToken } = _configs if (pbtc) this.pbtc = !Array.isArray(pbtc) ? new pBTC(pbtc) : pbtc.map(_el => new pBTC(_el)) if (pltc) this.pltc = !Array.isArray(pltc) ? new pLTC(pltc) : pltc.map(_el => new pLTC(_el)) @@ -31,6 +32,16 @@ class pTokens { } } + if (pbep20) { + if (Array.isArray(pbep20)) { + pbep20.forEach(_pbep20 => { + this[_pbep20.pToken.toLowerCase()] = new pBEP20(_pbep20) + }) + } else { + this[pbep20.pToken.toLowerCase()] = new pBEP20(pbep20) + } + } + if (peosioToken) { if (Array.isArray(peosioToken)) { peosioToken.forEach(_peostoken => { diff --git a/packages/ptokens/types/index.d.ts b/packages/ptokens/types/index.d.ts index f3282a5c..39482362 100644 --- a/packages/ptokens/types/index.d.ts +++ b/packages/ptokens/types/index.d.ts @@ -12,6 +12,7 @@ import { pBTCConfigs } from 'ptokens-pbtc' import { pLTCConfigs } from 'ptokens-pltc' import { pRVNConfigs } from 'ptokens-prvn' import { pERC20Configs } from 'ptokens-perc20' +import { pBEP20Configs } from 'ptokens-pbep20' import { pEosioTokenConfigs } from 'ptokens-peosio-token' import { pDOGEConfigs} from 'ptokens-pdoge' import { HttpProvider } from 'ptokens-providers' @@ -21,6 +22,7 @@ export interface pTokensConfigs { pltc?: pLTCConfigs | pLTCConfigs[], prvn?: pRVNConfigs | pRVNConfigs[], perc20?: pERC20Configs | pERC20Configs[], + pbep20?: pBEP20Configs | pBEP20Configs[], pdoge?: pDOGEConfigs | pDOGEConfigs[], peosioToken?: pEosioTokenConfigs | pEosioTokenConfigs[] }