fix: approval for mintable tokens
MODIFY
src/root/POSRootChainManager.ts
src/root/POSRootChainManager.ts
@@ -127,11 +127,16 @@ export default class POSRootChainManager extends ContractsBase {
}
async approveERC20(rootToken: address, amount: BN | string, options?: SendOptions) {
- if (!this.erc20Predicate) {
+ const tokenType = this.posRootChainManager.methods.tokenToType(rootToken).call()
+ if (!tokenType) {
+ throw new Error('tokenType not found. Set it while mapping contract.')
+ }
+ const predicate = this.posRootChainManager.methods.tokenToType(tokenType).call()
+ if (!predicate) {
throw new Error('posERC20Predicate address not found. Set it while constructing MaticPOSClient.')
}
const txObject = this.getPOSERC20TokenContract(rootToken, true).methods.approve(
- this.erc20Predicate,
+ predicate,
this.formatUint256(amount)
)
const web3Options = await this.web3Client.fillOptions(txObject, true /* onRootChain */, options)
@@ -142,11 +147,16 @@ export default class POSRootChainManager extends ContractsBase {
}
async approveMaxERC20(rootToken: address, options?: SendOptions) {
- if (!this.erc20Predicate) {
+ const tokenType = this.posRootChainManager.methods.tokenToType(rootToken).call()
+ if (!tokenType) {
+ throw new Error('tokenType not found. Set it while mapping contract.')
+ }
+ const predicate = this.posRootChainManager.methods.tokenToType(tokenType).call()
+ if (!predicate) {
throw new Error('posERC20Predicate address not found. Set it while constructing MaticPOSClient.')
}
const txObject = this.getPOSERC20TokenContract(rootToken, true).methods.approve(
- this.erc20Predicate,
+ predicate,
'0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'
)
const web3Options = await this.web3Client.fillOptions(txObject, true /* onRootChain */, options)
@@ -160,8 +170,16 @@ export default class POSRootChainManager extends ContractsBase {
if (options && (!token || !userAddress)) {
throw new Error('token address or user address is missing')
}
+ const tokenType = this.posRootChainManager.methods.tokenToType(token).call()
+ if (!tokenType) {
+ throw new Error('tokenType not found. Set it while mapping contract.')
+ }
+ const predicate = this.posRootChainManager.methods.tokenToType(tokenType).call()
+ if (!predicate) {
+ throw new Error('posERC20Predicate not found. Set it while mapping contract.')
+ }
const allowance = await this.getPOSERC20TokenContract(token, true)
- .methods.allowance(userAddress, this.erc20Predicate)
+ .methods.allowance(userAddress, predicate)
.call()
return allowance
@@ -195,11 +213,16 @@ export default class POSRootChainManager extends ContractsBase {
}
async approveERC721(rootToken: address, tokenId: BN | string, options?: SendOptions) {
- if (!this.erc721Predicate) {
+ const tokenType = this.posRootChainManager.methods.tokenToType(rootToken).call()
+ if (!tokenType) {
+ throw new Error('tokenType not found. Set it while mapping contract.')
+ }
+ const predicate = this.posRootChainManager.methods.tokenToType(tokenType).call()
+ if (!predicate) {
throw new Error('posERC721Predicate address not found. Set it while constructing MaticPOSClient.')
}
const txObject = this.getPOSERC721TokenContract(rootToken, true).methods.approve(
- this.erc721Predicate,
+ predicate,
this.formatUint256(tokenId)
)
const web3Options = await this.web3Client.fillOptions(txObject, true /* onRootChain */, options)
@@ -213,21 +236,31 @@ export default class POSRootChainManager extends ContractsBase {
if (options && !token) {
throw new Error('token address is missing')
}
+ const tokenType = this.posRootChainManager.methods.tokenToType(token).call()
+ if (!tokenType) {
+ throw new Error('tokenType not found. Set it while mapping contract.')
+ }
+ const predicate = this.posRootChainManager.methods.tokenToType(tokenType).call()
+ if (!predicate) {
+ throw new Error('posERC20Predicate not found. Set it while mapping contract.')
+ }
const approved = await this.getPOSERC721TokenContract(token, true)
.methods.getApproved(tokenId)
.call()
- return approved == this.erc721Predicate
+ return approved == predicate
}
async approveAllERC721(rootToken: address, options?: SendOptions) {
- if (!this.erc721Predicate) {
+ const tokenType = this.posRootChainManager.methods.tokenToType(rootToken).call()
+ if (!tokenType) {
+ throw new Error('tokenType not found. Set it while mapping contract.')
+ }
+ const predicate = this.posRootChainManager.methods.tokenToType(tokenType).call()
+ if (!predicate) {
throw new Error('posERC721Predicate address not found. Set it while constructing MaticPOSClient.')
}
- const txObject = this.getPOSERC721TokenContract(rootToken, true).methods.setApprovalForAll(
- this.erc721Predicate,
- true
- )
+ const txObject = this.getPOSERC721TokenContract(rootToken, true).methods.setApprovalForAll(predicate, true)
const web3Options = await this.web3Client.fillOptions(txObject, true /* onRootChain */, options)
if (web3Options.encodeAbi) {
return Object.assign(web3Options, { data: txObject.encodeABI(), to: rootToken })
@@ -239,8 +272,16 @@ export default class POSRootChainManager extends ContractsBase {
if (options && !token) {
throw new Error('token address is missing')
}
+ const tokenType = this.posRootChainManager.methods.tokenToType(token).call()
+ if (!tokenType) {
+ throw new Error('tokenType not found. Set it while mapping contract.')
+ }
+ const predicate = this.posRootChainManager.methods.tokenToType(tokenType).call()
+ if (!predicate) {
+ throw new Error('posERC20Predicate not found. Set it while mapping contract.')
+ }
const approved = await this.getPOSERC721TokenContract(token, true)
- .methods.isApprovedForAll(userAddress, this.erc721Predicate)
+ .methods.isApprovedForAll(userAddress, predicate)
.call()
return approved
@@ -314,13 +355,15 @@ export default class POSRootChainManager extends ContractsBase {
}
async approveERC1155(rootToken: address, options?: SendOptions) {
- if (!this.erc1155Predicate) {
+ const tokenType = this.posRootChainManager.methods.tokenToType(rootToken).call()
+ if (!tokenType) {
+ throw new Error('tokenType not found. Set it while mapping contract.')
+ }
+ const predicate = this.posRootChainManager.methods.tokenToType(tokenType).call()
+ if (!predicate) {
throw new Error('posERC1155Predicate address not found. Set it while constructing MaticPOSClient.')
}
- const txObject = this.getPOSERC1155TokenContract(rootToken, true).methods.setApprovalForAll(
- this.erc1155Predicate,
- true
- )
+ const txObject = this.getPOSERC1155TokenContract(rootToken, true).methods.setApprovalForAll(predicate, true)
const web3Options = await this.web3Client.fillOptions(txObject, true /* onRootChain */, options)
if (web3Options.encodeAbi) {
return Object.assign(web3Options, { data: txObject.encodeABI(), to: rootToken })

fix: approval for mintable tokens