chg: add methods for pos erc721
MODIFY
src/index.ts
src/index.ts
@@ -67,6 +67,44 @@ export class MaticPOSClient extends SDKClient {
}
return this.posRootChainManager.exitERC20(txHash, options)
}
+
+ approveERC721ForDeposit(rootToken: address, tokenId: BN | string, options?: SendOptions) {
+ if (options && (!options.from || !tokenId || !rootToken)) {
+ throw new Error('options.from, rootToken or tokenId is missing')
+ }
+ return this.posRootChainManager.approveERC721(rootToken, tokenId, options)
+ }
+
+ depositERC721ForUser(rootToken: address, user: address, tokenId: BN | string, options?: SendOptions) {
+ if (options && (!options.from || !tokenId || !rootToken || !user)) {
+ throw new Error('options.from, rootToken, user, or tokenId is missing')
+ }
+ return this.posRootChainManager.depositERC721ForUser(rootToken, tokenId, user, options)
+ }
+
+ burnERC721(childToken: address, tokenId: BN | string, options?: SendOptions) {
+ if (!this.web3Client.web3.utils.isAddress(this.web3Client.web3.utils.toChecksumAddress(childToken))) {
+ throw new Error(`${childToken} is not a valid token address`)
+ }
+ if (!tokenId) {
+ // ${tokenId} will stringify it while printing which might be a problem
+ throw new Error(`${tokenId} is not a tokenId`)
+ }
+ if (options && !options.from) {
+ throw new Error(`options.from is missing`)
+ }
+ return this.posRootChainManager.burnERC721(childToken, tokenId, options)
+ }
+
+ exitERC721(txHash: string, options?: SendOptions) {
+ if (!txHash) {
+ throw new Error(`txHash not provided`)
+ }
+ if (options && !options.from) {
+ throw new Error(`options.from is missing`)
+ }
+ return this.posRootChainManager.exitERC721(txHash, options)
+ }
}
export default class Matic extends SDKClient {

MODIFY
src/root/POSRootChainManager.ts
src/root/POSRootChainManager.ts
@@ -11,6 +11,7 @@ import RootChain from './RootChain'
import ExitManager from '../common/ExitManager'
const ERC20_TRANSFER_EVENT_SIG = '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef'
+const ERC721_TRANSFER_EVENT_SIG = '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef'
const abiCoder: ethers.utils.AbiCoder = ethers.utils.defaultAbiCoder
@@ -92,4 +93,49 @@ export default class POSRootChainManager extends ContractsBase {
}
return this.web3Client.send(txObject, _options)
}
+
+ async approveERC721(rootToken: address, tokenId: BN | string, options?: SendOptions) {
+ if (!this.erc721Predicate) {
+ throw new Error('Set posERC721Predicate while constructing client')
+ }
+ const txObject = this.getPOSERC721TokenContract(rootToken, true).methods.approve(
+ this.erc721Predicate,
+ this.formatUint256(tokenId)
+ )
+ 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 depositERC721ForUser(rootToken: address, tokenId: BN | string, user: address, options?: SendOptions) {
+ const depositData = abiCoder.encode(['uint256'], [this.formatUint256(tokenId)])
+ const txObject = this.posRootChainManager.methods.depositFor(user, rootToken, depositData)
+ 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 burnERC721(childToken: address, tokenId: BN | string, options?: SendOptions) {
+ const childTokenContract = this.getPOSERC721TokenContract(childToken)
+ const txObject = childTokenContract.methods.withdraw(this.formatUint256(tokenId))
+ 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 exitERC721(burnTxHash, options?) {
+ const payload = await this.exitManager.buildPayloadForExit(burnTxHash, ERC721_TRANSFER_EVENT_SIG)
+ const txObject = this.posRootChainManager.methods.exit(payload)
+ 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)
+ }
}

chg: add methods for pos erc721