Skip to content
This repository was archived by the owner on Dec 21, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ export type StrictStreamrClientOptions = {
}
}

export type StreamrClientOptions = Partial<Omit<StrictStreamrClientOptions, 'dataUnion'> & { dataUnion: Partial<StrictStreamrClientOptions['dataUnion']>}>
export type StreamrClientOptions = Partial<Omit<StrictStreamrClientOptions, 'dataUnion'> & {
dataUnion: Partial<StrictStreamrClientOptions['dataUnion']>
}>

const { ControlMessage } = ControlLayer
const { StreamMessage } = MessageLayer
Expand Down Expand Up @@ -87,7 +89,9 @@ export default function ClientConfig(opts: StreamrClientOptions = {}) {
tokenAddress: '0x0Cf0Ee63788A0849fE5297F3407f701E122cC023',
dataUnion: {
minimumWithdrawTokenWei: '1000000', // Threshold value set in AMB configs, smallest token amount to pass over the bridge
freeWithdraw: false, // if someone else pays for the gas when transporting the withdraw tx to mainnet; otherwise the client does the transport as self-service and pays the mainnet gas costs
// if someone else pays for the gas when transporting the withdraw tx to mainnet;
// otherwise the client does the transport as self-service and pays the mainnet gas costs
freeWithdraw: false,
factoryMainnetAddress: '0x7d55f9981d4E10A193314E001b96f72FCc901e40',
factorySidechainAddress: '0x1b55587Beea0b5Bc96Bb2ADa56bD692870522e9f',
templateMainnetAddress: '0x5FE790E3751dd775Cb92e9086Acd34a2adeB8C7b',
Expand Down
4 changes: 3 additions & 1 deletion src/Connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,9 @@ export default class Connection extends EventEmitter {

constructor(options = {}, debug?: Debug.Debugger) {
super()
this._debug = (debug !== undefined) ? debug.extend(counterId(this.constructor.name)) : Debug(`StreamrClient::${counterId(this.constructor.name)}`)
this._debug = debug !== undefined
? debug.extend(counterId(this.constructor.name))
: Debug(`StreamrClient::${counterId(this.constructor.name)}`)

this.options = options
this.options.autoConnect = !!this.options.autoConnect
Expand Down
43 changes: 19 additions & 24 deletions src/dataunion/Contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ import { StreamrClient } from '../StreamrClient'

const log = debug('StreamrClient::DataUnion')

function validateAddress(name: string, address: EthereumAddress) {
if (!isAddress(address)) {
throw new Error(`${name} is ${address ? 'not a valid Ethereum address' : 'missing'}`)
}
}

export class Contracts {

ethereum: StreamrEthereum
Expand Down Expand Up @@ -41,13 +47,8 @@ export class Contracts {
}

getDataUnionMainnetAddress(dataUnionName: string, deployerAddress: EthereumAddress) {
if (!isAddress(this.factoryMainnetAddress)) {
throw new Error('StreamrClient factoryMainnetAddress configuration is ' + (this.factoryMainnetAddress ? 'not a valid Ethereum address' : 'missing'))
}

if (!isAddress(this.templateMainnetAddress)) {
throw new Error('StreamrClient templateMainnetAddress configuration is ' + (this.templateMainnetAddress ? 'not a valid Ethereum address' : 'missing'))
}
validateAddress('StreamrClient factoryMainnetAddress', this.factoryMainnetAddress)
validateAddress('StreamrClient templateMainnetAddress', this.templateMainnetAddress)
// This magic hex comes from https://github.com/streamr-dev/data-union-solidity/blob/master/contracts/CloneLib.sol#L19
const codeHash = keccak256(`0x3d602d80600a3d3981f3363d3d373d3d3d363d73${this.templateMainnetAddress.slice(2)}5af43d82803e903d91602b57fd5bf3`)
const salt = keccak256(defaultAbiCoder.encode(['string', 'address'], [dataUnionName, deployerAddress]))
Expand All @@ -61,24 +62,18 @@ export class Contracts {
}

getDataUnionSidechainAddress(mainnetAddress: EthereumAddress) {
if (!isAddress(this.factorySidechainAddress)) {
throw new Error('StreamrClient factorySidechainAddress configuration is ' + (this.factorySidechainAddress ? 'not a valid Ethereum address' : 'missing'))
}

if (!isAddress(this.templateSidechainAddress)) {
throw new Error('StreamrClient templateSidechainAddress configuration is ' + (this.templateSidechainAddress ? 'not a valid Ethereum address' : 'missing'))
}
validateAddress('StreamrClient factorySidechainAddress', this.factorySidechainAddress)
validateAddress('StreamrClient templateSidechainAddress', this.templateSidechainAddress)
// This magic hex comes from https://github.com/streamr-dev/data-union-solidity/blob/master/contracts/CloneLib.sol#L19
const codeHash = keccak256(`0x3d602d80600a3d3981f3363d3d373d3d3d363d73${this.templateSidechainAddress.slice(2)}5af43d82803e903d91602b57fd5bf3`)
const code = `0x3d602d80600a3d3981f3363d3d373d3d3d363d73${this.templateSidechainAddress.slice(2)}5af43d82803e903d91602b57fd5bf3`
const codeHash = keccak256(code)
return getCreate2Address(this.factorySidechainAddress, hexZeroPad(mainnetAddress, 32), codeHash)
}

getMainnetContractReadOnly(contractAddress: EthereumAddress) {
if (isAddress(contractAddress)) {
const provider = this.ethereum.getMainnetProvider()
return new Contract(contractAddress, dataUnionMainnetABI, provider)
}
throw new Error(`${contractAddress} was not a good Ethereum address`)
validateAddress('contractAddress', contractAddress)
const provider = this.ethereum.getMainnetProvider()
return new Contract(contractAddress, dataUnionMainnetABI, provider)
}

getMainnetContract(contractAddress: EthereumAddress) {
Expand Down Expand Up @@ -298,12 +293,12 @@ export class Contracts {
throw new Error(`Mainnet data union "${duName}" contract ${duMainnetAddress} already exists!`)
}

if (!isAddress(this.factoryMainnetAddress)) {
throw new Error('StreamrClient has invalid factoryMainnetAddress configuration.')
}
validateAddress('StreamrClient factoryMainnetAddress', this.factoryMainnetAddress)

if (await mainnetProvider.getCode(this.factoryMainnetAddress) === '0x') {
throw new Error(`Data union factory contract not found at ${this.factoryMainnetAddress}, check StreamrClient.options.dataUnion.factoryMainnetAddress!`)
throw new Error(
`Data union factory contract not found at ${this.factoryMainnetAddress}, check StreamrClient.options.dataUnion.factoryMainnetAddress!`
)
}

const factoryMainnet = new Contract(this.factoryMainnetAddress!, factoryMainnetABI, mainnetWallet)
Expand Down
5 changes: 4 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ export * from './dataunion/DataUnion'
export * from './rest/authFetch'
export * from './types'

// TODO should export these to support StreamMessageAsObject: export { StreamMessageType, ContentType, EncryptionType, SignatureType } from 'streamr-client-protocol/dist/src/protocol/message_layer/StreamMessage'
// TODO should export these to support StreamMessageAsObject:
// export {
// StreamMessageType, ContentType, EncryptionType, SignatureType
// } from 'streamr-client-protocol/dist/src/protocol/message_layer/StreamMessage'
export { BigNumber } from '@ethersproject/bignumber'
export { ConnectionInfo } from '@ethersproject/web'
export { Contract } from '@ethersproject/contracts'
Expand Down
3 changes: 0 additions & 3 deletions test/benchmarks/publish.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
const { format } = require('util')

const { Benchmark } = require('benchmark')

// eslint-disable-next-line import/no-unresolved
const StreamrClient = require('../../dist')
const config = require('../integration/config')

console.log('StreamrClient', { StreamrClient })

/* eslint-disable no-console */

let count = 100000 // pedantic: use large initial number so payload size is similar
Expand Down
1 change: 0 additions & 1 deletion test/benchmarks/subscribe.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const { format } = require('util')

const { Benchmark } = require('benchmark')

// eslint-disable-next-line import/no-unresolved
Expand Down
2 changes: 1 addition & 1 deletion test/integration/dataunion/signature.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ describe('DataUnion signature', () => {
const isValid3 = await sidechainContract.signatureIsValid(memberWallet.address, member2Wallet.address, '3000000000000000', signature3)
log(`Signature for all tokens ${memberWallet.address} -> ${member2Wallet.address}: ${signature}, checked ${isValid ? 'OK' : '!!!BROKEN!!!'}`)
log(`Signature for 1 token ${memberWallet.address} -> ${member2Wallet.address}: ${signature2}, checked ${isValid2 ? 'OK' : '!!!BROKEN!!!'}`)
// eslint-disable-next-line max-len
log(`Signature for 0.003 tokens ${memberWallet.address} -> ${member2Wallet.address}: ${signature3}, checked ${isValid3 ? 'OK' : '!!!BROKEN!!!'}`)
log(`sidechainDU(${sidechainContract.address}) token bal ${await tokenSidechain.balanceOf(sidechainContract.address)}`)

expect(isValid).toBe(true)
expect(isValid2).toBe(true)
expect(isValid3).toBe(true)
}, 100000)

})
7 changes: 6 additions & 1 deletion test/integration/dataunion/stats.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,12 @@ describe('DataUnion stats', () => {
}, 150000)

it('member stats', async () => {
const memberStats = await Promise.all(activeMemberAddressList.concat([inactiveMember]).map((m) => queryClient.getDataUnion(dataUnion.getAddress()).getMemberStats(m)))
const memberStats = await Promise.all(
activeMemberAddressList
.concat([inactiveMember])
.map((m) => queryClient.getDataUnion(dataUnion.getAddress()).getMemberStats(m))
)

const ZERO = BigNumber.from(0)
expect(memberStats).toMatchObject([{
status: MemberStatus.ACTIVE,
Expand Down