remove duplicate _fillOptions
MODIFY
.gitignore
.gitignore
@@ -8,7 +8,7 @@ test-blockchain/geth
test-blockchain/history
test-blockchain/data/**
!test-blockchain/data/.gitkeep
-.env
+*.env
bundle.js

MODIFY
src/common/ContractsBase.ts
src/common/ContractsBase.ts
-import Web3Client from './Web3Client'
import BN from 'bn.js'
-import ChildERC20Artifact from 'matic-protocol/contracts-core/artifacts/ChildERC20.json'
-import ChildERC721Artifact from 'matic-protocol/contracts-core/artifacts/ChildERC721.json'
-import ChildMaticArtifact from 'matic-protocol/contracts-core/artifacts/MaticChildERC20.json'
+
+import Web3Client from './Web3Client'
+import network from './matic-protocol'
+
import { address } from '../types/Common'
export default class ContractsBase {
+ static MATIC_CHILD_TOKEN: address = '0x0000000000000000000000000000000000001010'
+
web3Client: Web3Client
constructor(web3Client: Web3Client) {
@@ -26,50 +28,23 @@ export default class ContractsBase {
public getERC20TokenContract(token: address, parent: boolean = false) {
const web3 = parent ? this.web3Client.parentWeb3 : this.web3Client.web3
- return new web3.eth.Contract(ChildERC20Artifact.abi, token)
+ return new web3.eth.Contract(network.abi('ChildERC20'), token)
}
public getERC721TokenContract(token: address, parent: boolean = false) {
const web3 = parent ? this.web3Client.parentWeb3 : this.web3Client.web3
- return new web3.eth.Contract(ChildERC721Artifact.abi, token)
+ return new web3.eth.Contract(network.abi('ChildERC721'), token)
}
- public getChildMaticContract(childMaticAddress: address) {
- return new this.web3Client.web3.eth.Contract(ChildMaticArtifact.abi, childMaticAddress)
+ public getChildMaticContract() {
+ return new this.web3Client.web3.eth.Contract(network.abi('MRC20'), ContractsBase.MATIC_CHILD_TOKEN)
}
- async _fillOptions(options, txObject, web3) {
- delete txObject.chainId
- const from = options.from
- if (!from) {
- throw new Error('`from` required in options or set wallet using maticObject.wallet = <private key>')
- }
-
- const [gasLimit, gasPrice, nonce, chainId] = await Promise.all([
- !(options.gasLimit || options.gas)
- ? txObject.estimateGas({ from, value: options.value })
- : options.gasLimit || options.gas,
- !options.gasPrice ? web3.eth.getGasPrice() : options.gasPrice,
- !options.nonce ? web3.eth.getTransactionCount(from, 'pending') : options.nonce,
- !options.chainId ? web3.eth.net.getId() : options.chainId,
- ])
- return {
- from,
- gas: this.encode(gasLimit),
- gasPrice: this.encode(gasPrice),
- nonce,
- chainId,
- value: options.value || 0,
- to: options.to || null,
- data: options.data,
- }
- }
-
- wrapWeb3Promise(promise, options) {
- const _emptyFunc = () => {}
- return promise
- .on('transactionHash', options.onTransactionHash || _emptyFunc)
- .on('receipt', options.onReceipt || _emptyFunc)
- .on('error', options.onError || _emptyFunc)
- }
+ // wrapWeb3Promise(promise, options) {
+ // const _emptyFunc = () => {}
+ // return promise
+ // .on('transactionHash', options.onTransactionHash || _emptyFunc)
+ // .on('receipt', options.onReceipt || _emptyFunc)
+ // .on('error', options.onError || _emptyFunc)
+ // }
}

MODIFY
src/common/SDKClient.ts
src/common/SDKClient.ts
@@ -6,7 +6,6 @@ import ContractsBase from '../common/ContractsBase'
export default class Matic extends ContractsBase {
public web3Client: Web3Client
-
constructor(options: any = {}) {
const web3Client = new Web3Client(
options.parentProvider,
@@ -59,21 +58,12 @@ export default class Matic extends ContractsBase {
if (options && (!options.from || !amount || !token || !to)) {
throw new Error('options.from, to, token or amount is missing')
}
-
const txObject = this.getERC20TokenContract(token, options.parent).methods.transfer(to, this.encode(amount))
-
- const _options = await this._fillOptions(
- options,
- txObject,
- options.parent ? this.web3Client.getParentWeb3() : this.web3Client.getMaticWeb3()
- )
-
- if (options.encodeAbi) {
- _options.data = txObject.encodeABI()
- _options.to = token
- return _options
+ const onRootChain = options.parent ? true : false
+ const _options = await this.web3Client.fillOptions(txObject, onRootChain, options)
+ if (_options.encodeAbi) {
+ return Object.assign(_options, { data: txObject.encodeABI(), to: token })
}
-
return this.web3Client.send(txObject, _options)
}
@@ -83,19 +73,26 @@ export default class Matic extends ContractsBase {
}
const txObject = this.getERC721TokenContract(token, options.parent).methods.transferFrom(options.from, to, tokenId)
-
- const _options = await this._fillOptions(
- options,
- txObject,
- options.parent ? this.web3Client.getParentWeb3() : this.web3Client.getMaticWeb3()
- )
-
- if (options.encodeAbi) {
- _options.data = txObject.encodeABI()
- _options.to = token
- return _options
+ const onRootChain = options.parent ? true : false
+ const _options = await this.web3Client.fillOptions(txObject, onRootChain, options)
+ if (_options.encodeAbi) {
+ return Object.assign(_options, { data: txObject.encodeABI(), to: token })
+ }
+ return this.web3Client.send(txObject, _options)
}
+ async transferMaticEth(to: address, amount: BN | string, options?: SendOptions) {
+ console.log(to, this.encode(amount))
+ if (options && (!options.from || !amount || !to)) {
+ throw new Error('options.from, to or amount is missing')
+ }
+ const token = ContractsBase.MATIC_CHILD_TOKEN
+ const txObject = this.getChildMaticContract().methods.transfer(to, this.encode(amount))
+ options.value = this.encode(amount)
+ const _options = await this.web3Client.fillOptions(txObject, false /* onRootChain */, options)
+ if (_options.encodeAbi) {
+ return Object.assign(_options, { data: txObject.encodeABI(), to: token })
+ }
return this.web3Client.send(txObject, _options)
}
}

MODIFY
src/common/Web3Client.ts
src/common/Web3Client.ts
import Web3 from 'web3'
-import { SendOptions } from '../types/Common'
+import { SendOptions, address } from '../types/Common'
export default class Web3Client {
public parentWeb3: Web3
@@ -23,9 +23,15 @@ export default class Web3Client {
return method.call(options || this.parentDefaultOptions)
}
- async _fillOptions(options, txObject, web3) {
- const _options = options || this.parentDefaultOptions
- if (!_options.from) return new Error('from is not specified')
+ async fillOptions(txObject: any, onRootChain: boolean, options?: SendOptions) {
+ if (onRootChain) {
+ return this._fillOptions(txObject, this.parentWeb3, options || this.parentDefaultOptions)
+ }
+ return this._fillOptions(txObject, this.web3, options || this.maticDefaultOptions)
+ }
+
+ async _fillOptions(txObject, web3, _options) {
+ if (!_options.from) throw new Error('from is not specified')
const from = _options.from
delete txObject.chainId
@@ -45,9 +51,10 @@ export default class Web3Client {
gasPrice,
nonce,
chainId,
- value: options.value || 0,
- to: options.to || null,
- data: options.data,
+ value: _options.value || 0,
+ to: _options.to || null,
+ data: _options.data,
+ encodeAbi: _options.encodeAbi || false,
}
}
@@ -77,9 +84,14 @@ export default class Web3Client {
// apparently even when provided with a buffer of 20k, the call reverts. This shouldn't be happening because the actual gas used is less than what the estimation returns
// providing higher buffer for now
// @todo handle hex values of gas
- _options.gas = options.parent ? _options.gas + 1000000 : _options.gas
- _options.gasPrice = options.parent ? _options.gasPrice : 0
-
+ if (options.parent) {
+ _options.gas = (_options.gas || this.parentDefaultOptions.gas) + 1000000
+ _options.gasPrice = _options.gasPrice || this.parentDefaultOptions.gasPrice
+ } else {
+ _options.gas = _options.gas || this.maticDefaultOptions.gas
+ _options.gasPrice = _options.gasPrice || this.maticDefaultOptions.gasPrice
+ }
+ console.log('sending tx with', { _options })
return this.wrapWeb3Promise(txObject.send(_options), _options)
}

ADD
src/common/matic-protocol.ts
+const Network = require('@maticnetwork/meta/network')
+
+const network = new Network('testnet', 'cs-2007')
+export default network

MODIFY
src/index.ts
src/index.ts
@@ -103,15 +103,11 @@ export default class Matic extends SDKClient {
value,
})
}
-
Object.assign(options, { value, to })
-
- const _options = await this._fillOptions(options, {}, web3Object)
- if (options.encodeAbi) {
- return _options
- }
-
- return this.web3Client.wrapWeb3Promise(web3Object.eth.sendTransaction(_options), _options)
+ const _options = await this.web3Client.fillOptions(options /* txObject */, true /* onRootChain */, options)
+ return _options.encodeAbi
+ ? _options
+ : this.web3Client.wrapWeb3Promise(web3Object.eth.sendTransaction(_options), _options)
}
depositEther(amount: BN | string, options?: SendOptions) {
@@ -192,9 +188,7 @@ export default class Matic extends SDKClient {
sellOrder.expiry,
to
)
-
- const _options = await this._fillOptions(options, txObj, this.web3Client.getMaticWeb3())
-
+ const _options = await this.web3Client.fillOptions(txObj, false /* onRootChain */, options)
return this.web3Client.send(txObj, _options)
}
@@ -214,15 +208,10 @@ export default class Matic extends SDKClient {
this.depositManager.getAddress(),
tokenId
)
-
- const _options = await this._fillOptions(options, txObject, this.web3Client.getParentWeb3())
-
- if (options.encodeAbi) {
- _options.data = txObject.encodeABI()
- _options.to = token
- return _options
+ const _options = await this.web3Client.fillOptions(txObject, true /* onRootChain */, options)
+ if (_options.encodeAbi) {
+ return Object.assign(_options, { data: txObject.encodeABI(), to: token })
}
-
return this.web3Client.send(txObject, _options)
}

MODIFY
src/root/DepositManager.ts
src/root/DepositManager.ts
import BN from 'bn.js'
import bluebird from 'bluebird'
import Contract from 'web3/eth/contract'
-import DepositManagerArtifact from 'matic-protocol/contracts-core/artifacts/DepositManager.json'
-import ChildChainArtifact from 'matic-protocol/contracts-core/artifacts/ChildChain.json'
+
+import network from '../common/matic-protocol'
import ContractsBase from '../common/ContractsBase'
import { address, SendOptions } from '../types/Common'
@@ -20,7 +20,7 @@ export default class DepositManager extends ContractsBase {
constructor(depositManager: address, web3Client: Web3Client, registry: Registry) {
super(web3Client)
this.depositManagerContract = new this.web3Client.parentWeb3.eth.Contract(
- DepositManagerArtifact.abi,
+ network.abi('DepositManager'),
depositManager
)
this.registry = registry
@@ -28,7 +28,7 @@ export default class DepositManager extends ContractsBase {
async initialize() {
const childChainAddress = (await this.registry.registry.methods.getChildChainAndStateSender().call())[0]
- this.childChainContract = new this.web3Client.web3.eth.Contract(ChildChainArtifact.abi, childChainAddress)
+ this.childChainContract = new this.web3Client.web3.eth.Contract(network.abi('ChildChain'), childChainAddress)
}
async depositStatusFromTxHash(txHash: string) {
@@ -62,29 +62,19 @@ export default class DepositManager extends ContractsBase {
this.depositManagerContract.options.address,
this.encode(amount)
)
-
- const _options = await this._fillOptions(options, txObject, this.web3Client.getParentWeb3())
-
- if (options.encodeAbi) {
- _options.data = txObject.encodeABI()
- _options.to = token
- return _options
+ const _options = await this.web3Client.fillOptions(txObject, true /* onRootChain */, options)
+ if (_options.encodeAbi) {
+ return Object.assign(_options, { data: txObject.encodeABI(), to: token })
}
-
return this.web3Client.send(txObject, _options)
}
async depositERC20(token: address, amount: BN | string, options?: SendOptions) {
const txObject = this.depositManagerContract.methods.depositERC20(token, this.encode(amount))
-
- const _options = await this._fillOptions(options, txObject, this.web3Client.getParentWeb3())
-
- if (options.encodeAbi) {
- _options.data = txObject.encodeABI()
- _options.to = this.depositManagerContract.options.address
- return _options
+ const _options = await this.web3Client.fillOptions(txObject, true /* onRootChain */, options)
+ if (_options.encodeAbi) {
+ return Object.assign(_options, { data: txObject.encodeABI(), to: this.depositManagerContract.options.address })
}
-
return this.web3Client.send(txObject, _options)
}
@@ -101,14 +91,10 @@ export default class DepositManager extends ContractsBase {
async depositERC20ForUser(token: address, amount: BN | string, user: address, options?: SendOptions) {
const txObject = this.depositManagerContract.methods.depositERC20ForUser(token, user, this.encode(amount))
- const _options = await this._fillOptions(options, txObject, this.web3Client.getParentWeb3())
-
- if (options.encodeAbi) {
- _options.data = txObject.encodeABI()
- _options.to = this.depositManagerContract.options.address
- return _options
+ const _options = await this.web3Client.fillOptions(txObject, true /* onRootChain */, options)
+ if (_options.encodeAbi) {
+ return Object.assign(_options, { data: txObject.encodeABI(), to: this.depositManagerContract.options.address })
}
-
return this.web3Client.send(txObject, _options)
}
@@ -118,19 +104,14 @@ export default class DepositManager extends ContractsBase {
async depositEther(amount: BN | string, options: SendOptions = {}) {
const txObject = this.depositManagerContract.methods.depositEther()
-
- const _options = await this._fillOptions(
- Object.assign(options, { value: this.encode(amount) }),
+ const _options = await this.web3Client.fillOptions(
txObject,
- this.web3Client.getParentWeb3()
+ true /* onRootChain */,
+ Object.assign(options, { value: this.encode(amount) })
)
-
- if (options.encodeAbi) {
- _options.data = txObject.encodeABI()
- _options.to = this.depositManagerContract.options.address
- return _options
+ if (_options.encodeAbi) {
+ return Object.assign(_options, { data: txObject.encodeABI(), to: this.depositManagerContract.options.address })
}
-
return this.web3Client.send(txObject, _options)
}

MODIFY
src/root/POSRootChainManager.ts
src/root/POSRootChainManager.ts
@@ -30,74 +30,51 @@ export default class POSRootChainManager extends ContractsBase {
this.posRootChainManager.options.address,
this.encode(amount)
)
-
- const _options = await this._fillOptions(options, txObject, this.web3Client.getParentWeb3())
-
- if (options.encodeAbi) {
- _options.data = txObject.encodeABI()
- _options.to = rootToken
- return _options
+ const _options = await this.web3Client.fillOptions(txObject, true /* onRootChain */, options)
+ if (_options.encodeAbi) {
+ return Object.assign(_options, { data: txObject.encodeABI(), to: rootToken })
}
-
return this.web3Client.send(txObject, _options)
}
async depositERC20ForUser(rootToken: address, amount: BN | string, user: address, options?: SendOptions) {
const txObject = this.posRootChainManager.methods.depositFor(user, rootToken, this.encode(amount))
- const _options = await this._fillOptions(options, txObject, this.web3Client.getParentWeb3())
-
- if (options.encodeAbi) {
- _options.data = txObject.encodeABI()
- _options.to = this.posRootChainManager.options.address
- return _options
+ const _options = await this.web3Client.fillOptions(txObject, true /* onRootChain */, options)
+ if (_options.encodeAbi) {
+ return Object.assign(_options, { data: txObject.encodeABI(), to: this.posRootChainManager.options.address })
}
-
return this.web3Client.send(txObject, _options)
}
async depositEtherForUser(amount: BN | string, user: address, options: SendOptions = {}) {
const txObject = this.posRootChainManager.methods.depositEtherFor(user)
-
- const _options = await this._fillOptions(
- Object.assign(options, { value: this.encode(amount) }),
+ const _options = await this.web3Client.fillOptions(
txObject,
- this.web3Client.getParentWeb3()
+ true /* onRootChain */,
+ Object.assign(options, { value: this.encode(amount) })
)
-
- if (options.encodeAbi) {
- _options.data = txObject.encodeABI()
- _options.to = this.posRootChainManager.options.address
- return _options
+ if (_options.encodeAbi) {
+ return Object.assign(_options, { data: txObject.encodeABI(), to: this.posRootChainManager.options.address })
}
-
return this.web3Client.send(txObject, _options)
}
async burnERC20(childToken: address, amount: BN | string, options?: SendOptions) {
const childTokenContract = new this.web3Client.web3.eth.Contract(ChildTokenArtifact.abi, childToken)
const txObject = childTokenContract.methods.withdraw(this.encode(amount))
-
- const _options = await this._fillOptions(options, txObject, this.web3Client.getMaticWeb3())
-
- if (options.encodeAbi) {
- _options.data = txObject.encodeABI()
- _options.to = childToken
- return _options
+ const _options = await this.web3Client.fillOptions(txObject, false /* onRootChain */, options)
+ if (_options.encodeAbi) {
+ return Object.assign(_options, { data: txObject.encodeABI(), to: childToken })
}
-
return this.web3Client.send(txObject, _options)
}
async exitERC20(burnTxHash, options?) {
const payload = await this.exitManager.buildPayloadForExit(burnTxHash, TRANSFER_EVENT_SIG)
const txObject = this.posRootChainManager.methods.exit(payload)
-
- const _options = await this._fillOptions(options, txObject, this.web3Client.getParentWeb3())
-
- if (options.encodeAbi) {
- _options.data = txObject.encodeABI()
- _options.to = this.posRootChainManager.options.address
- return _options
+ const _options = await this.web3Client.fillOptions(txObject, true /* onRootChain */, options)
+ if (_options.encodeAbi) {
+ return Object.assign(_options, { data: txObject.encodeABI(), to: this.posRootChainManager.options.address })
}
return this.web3Client.send(txObject, _options)
}

MODIFY
src/root/Registry.ts
src/root/Registry.ts
import Contract from 'web3/eth/contract'
-import RegistryArtifact from 'matic-protocol/contracts-core/artifacts/Registry.json'
+import network from '../common/matic-protocol'
import ContractsBase from '../common/ContractsBase'
import { address } from '../types/Common'
import Web3Client from '../common/Web3Client'
@@ -10,6 +10,6 @@ export default class Registry extends ContractsBase {
constructor(registry: address, web3Client: Web3Client) {
super(web3Client)
- this.registry = new this.web3Client.parentWeb3.eth.Contract(RegistryArtifact.abi, registry)
+ this.registry = new this.web3Client.parentWeb3.eth.Contract(network.abi('Registry'), registry)
}
}

MODIFY
src/root/RootChain.ts
src/root/RootChain.ts
import Contract from 'web3/eth/contract'
-import RootChainArtifact from 'matic-protocol/contracts-core/artifacts/RootChain.json'
+import network from '../common/matic-protocol'
import ContractsBase from '../common/ContractsBase'
import { address } from '../types/Common'
import Web3Client from '../common/Web3Client'
@@ -11,7 +11,7 @@ export default class RootChain extends ContractsBase {
constructor(rootChain: address, web3Client: Web3Client) {
super(web3Client)
- this.rootChain = new this.web3Client.parentWeb3.eth.Contract(RootChainArtifact.abi, rootChain)
+ this.rootChain = new this.web3Client.parentWeb3.eth.Contract(network.abi('RootChain'), rootChain)
}
getLastChildBlock() {
@@ -29,10 +29,15 @@ export default class RootChain extends ContractsBase {
// binary search on all the checkpoints to find the checkpoint that contains the childBlockNumber
let ans
while (start.lte(end)) {
- if (start.eq(end)) { ans = start; break }
+ if (start.eq(end)) {
+ ans = start
+ break
+ }
let mid = start.add(end).div(new BN(2))
console.log({ start: start.toString(), mid: mid.toString(), end: end.toString() }) // eslint-disable-line
- const headerBlock = await this.web3Client.call(this.rootChain.methods.headerBlocks(mid.mul(new BN(10000)).toString()))
+ const headerBlock = await this.web3Client.call(
+ this.rootChain.methods.headerBlocks(mid.mul(new BN(10000)).toString())
+ )
// console.log('headerBlock', headerBlock)
const headerStart = new BN(headerBlock.start)
const headerEnd = new BN(headerBlock.end)

MODIFY
src/root/WithdrawManager.ts
src/root/WithdrawManager.ts
@@ -2,11 +2,7 @@ import ethUtils from 'ethereumjs-util'
import Contract from 'web3/eth/contract'
import BN from 'bn.js'
-import WithdrawManagerArtifact from 'matic-protocol/contracts-core/artifacts/WithdrawManager.json'
-import ERC20PredicateArtifact from 'matic-protocol/contracts-core/artifacts/ERC20Predicate.json'
-import ERC721PredicateArtifact from 'matic-protocol/contracts-core/artifacts/ERC721Predicate.json'
-import MintableERC721PredicateArtifact from 'matic-protocol/contracts-core/artifacts/MintableERC721Predicate.json'
-import ChildERC721MintableArtifact from 'matic-protocol/contracts-core/artifacts/ChildERC721Mintable.json'
+import network from '../common/matic-protocol'
import Proofs from 'matic-protocol/contracts-core/helpers/proofs.js'
import { address, SendOptions } from '../types/Common'
@@ -15,6 +11,7 @@ import ContractsBase from '../common/ContractsBase'
import RootChain from './RootChain'
import Registry from './Registry'
import ExitManager from '../common/ExitManager'
+import Matic from '../common/SDKClient'
const logger = {
info: require('debug')('maticjs:WithdrawManager'),
@@ -34,7 +31,7 @@ export default class WithdrawManager extends ContractsBase {
constructor(withdrawManager: address, rootChain: RootChain, web3Client: Web3Client, registry: Registry) {
super(web3Client)
- this.withdrawManager = new this.web3Client.parentWeb3.eth.Contract(WithdrawManagerArtifact.abi, withdrawManager)
+ this.withdrawManager = new this.web3Client.parentWeb3.eth.Contract(network.abi('WithdrawManager'), withdrawManager)
this.rootChain = rootChain
this.registry = registry
this.exitManager = new ExitManager(rootChain, web3Client)
@@ -43,38 +40,37 @@ export default class WithdrawManager extends ContractsBase {
async initialize() {
const erc20PredicateAddress = await this.registry.registry.methods.erc20Predicate().call()
const erc721PredicateAddress = await this.registry.registry.methods.erc721Predicate().call()
- this.erc20Predicate = new this.web3Client.parentWeb3.eth.Contract(ERC20PredicateArtifact.abi, erc20PredicateAddress)
+ this.erc20Predicate = new this.web3Client.parentWeb3.eth.Contract(
+ network.abi('ERC20Predicate'),
+ erc20PredicateAddress
+ )
this.erc721Predicate = new this.web3Client.parentWeb3.eth.Contract(
- ERC721PredicateArtifact.abi,
+ network.abi('ERC721Predicate'),
erc721PredicateAddress
)
}
async burnERC20Tokens(token: address, amount: BN | string, options?: SendOptions) {
- const txObject = this.getERC20TokenContract(token).methods.withdraw(this.encode(amount))
-
- const _options = await this._fillOptions(options, txObject, this.web3Client.getMaticWeb3())
-
- if (options.encodeAbi) {
- _options.data = txObject.encodeABI()
- _options.to = token
- return _options
+ let txObject
+ if (token === ContractsBase.MATIC_CHILD_TOKEN) {
+ txObject = this.getChildMaticContract().methods.withdraw(this.encode(amount))
+ options.value = this.encode(amount)
+ } else {
+ txObject = this.getERC20TokenContract(token).methods.withdraw(this.encode(amount))
+ }
+ const _options = await this.web3Client.fillOptions(txObject, false /* onRootChain */, options)
+ if (_options.encodeAbi) {
+ return Object.assign(_options, { data: txObject.encodeABI(), to: token })
}
-
return this.web3Client.send(txObject, _options)
}
async burnERC721Token(token: address, tokenId: BN | string, options?: SendOptions) {
const txObject = this.getERC721TokenContract(token).methods.withdraw(this.encode(tokenId))
-
- const _options = await this._fillOptions(options, txObject, this.web3Client.getMaticWeb3())
-
- if (options.encodeAbi) {
- _options.data = txObject.encodeABI()
- _options.to = token
- return _options
+ const _options = await this.web3Client.fillOptions(txObject, false /* onRootChain */, options)
+ if (_options.encodeAbi) {
+ return Object.assign(_options, { data: txObject.encodeABI(), to: token })
}
-
return this.web3Client.send(txObject, _options)
}
@@ -85,28 +81,19 @@ export default class WithdrawManager extends ContractsBase {
options.gas = 2000000
}
const txObject = this.withdrawManager.methods.processExits(token)
-
- const _options = await this._fillOptions(options, txObject, this.web3Client.getParentWeb3())
-
- if (options.encodeAbi) {
- _options.data = txObject.encodeABI()
- _options.to = this.withdrawManager.options.address
- return _options
+ const _options = await this.web3Client.fillOptions(txObject, true /* onRootChain */, options)
+ if (_options.encodeAbi) {
+ return Object.assign(_options, { data: txObject.encodeABI(), to: this.withdrawManager.options.address })
}
-
- return this.web3Client.send(txObject, options)
+ return this.web3Client.send(txObject, _options)
}
async startExitWithBurntERC20Tokens(burnTxHash, options?) {
const payload = await this.exitManager.buildPayloadForExit(burnTxHash, WithdrawManager.ERC20_WITHDRAW_EVENT_SIG)
const txObject = this.erc20Predicate.methods.startExitWithBurntTokens(payload)
-
- const _options = await this._fillOptions(options, txObject, this.web3Client.getParentWeb3())
-
- if (options.encodeAbi) {
- _options.data = txObject.encodeABI()
- _options.to = this.erc20Predicate.options.address
- return _options
+ const _options = await this.web3Client.fillOptions(txObject, true /* onRootChain */, options)
+ if (_options.encodeAbi) {
+ return Object.assign(_options, { data: txObject.encodeABI(), to: this.erc20Predicate.options.address })
}
return this.web3Client.send(txObject, _options)
}
@@ -114,13 +101,9 @@ export default class WithdrawManager extends ContractsBase {
async startExitWithBurntERC721Tokens(burnTxHash, options?) {
const payload = await this.exitManager.buildPayloadForExit(burnTxHash, WithdrawManager.ERC721_WITHDRAW_EVENT_SIG)
const txObject = this.erc721Predicate.methods.startExitWithBurntTokens(payload)
-
- const _options = await this._fillOptions(options, txObject, this.web3Client.getParentWeb3())
-
- if (options.encodeAbi) {
- _options.data = txObject.encodeABI()
- _options.to = this.erc721Predicate.options.address
- return _options
+ const _options = await this.web3Client.fillOptions(txObject, true /* onRootChain */, options)
+ if (_options.encodeAbi) {
+ return Object.assign(_options, { data: txObject.encodeABI(), to: this.erc721Predicate.options.address })
}
return this.web3Client.send(txObject, _options)
}
@@ -133,9 +116,9 @@ export default class WithdrawManager extends ContractsBase {
*/
async startExitForMintableBurntToken(burnTxHash, predicate: address, options?) {
const { payload, mint } = await this._buildPayloadAndFindMintTransaction(burnTxHash)
- const _predicate = new this.web3Client.parentWeb3.eth.Contract(MintableERC721PredicateArtifact.abi, predicate)
+ const _predicate = new this.web3Client.parentWeb3.eth.Contract(network.abi('MintableERC721Predicate'), predicate)
const txObject = _predicate.methods.startExitForMintableBurntToken(payload, mint)
- const _options = await this._fillOptions(options, txObject, this.web3Client.parentWeb3)
+ const _options = await this.web3Client.fillOptions(txObject, true /* onRootChain */, options)
return this.web3Client.send(txObject, _options)
}
@@ -147,9 +130,9 @@ export default class WithdrawManager extends ContractsBase {
*/
async startExitForMetadataMintableBurntToken(burnTxHash, predicate: address, options?) {
const { payload, mint } = await this._buildPayloadAndFindMintTransaction(burnTxHash)
- const _predicate = new this.web3Client.parentWeb3.eth.Contract(MintableERC721PredicateArtifact.abi, predicate)
+ const _predicate = new this.web3Client.parentWeb3.eth.Contract(network.abi('MintableERC721Predicate'), predicate)
const txObject = _predicate.methods.startExitForMetadataMintableBurntToken(payload, mint)
- const _options = await this._fillOptions(options, txObject, this.web3Client.parentWeb3)
+ const _options = await this.web3Client.fillOptions(txObject, true /* onRootChain */, options)
return this.web3Client.send(txObject, _options)
}
@@ -161,7 +144,7 @@ export default class WithdrawManager extends ContractsBase {
)
const tokenId = withdrawEvent.data
logger.debug({ burnTxHash, burnReceipt, withdrawEvent, tokenId })
- const contract = new this.web3Client.web3.eth.Contract(ChildERC721MintableArtifact.abi, burnReceipt.to)
+ const contract = new this.web3Client.web3.eth.Contract(network.abi('ChildERC721Mintable'), burnReceipt.to)
const mintEvents = await contract.getPastEvents('Transfer', {
filter: { tokenId },
fromBlock: 0,

remove duplicate _fillOptions