new: users: add transferWithSignature method
MODIFY
src/common/ContractsBase.ts
src/common/ContractsBase.ts
@@ -3,7 +3,7 @@ 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 transferWithSigABI from './transferWithSigABI.json'
import { address } from '../types/Common'
export default class ContractsBase {
@@ -25,6 +25,11 @@ export default class ContractsBase {
}
}
+ getTokenContractForTransferWithSig(token: address) {
+ const web3 = this.web3Client.web3
+ return new web3.eth.Contract(transferWithSigABI, token)
+ }
+
public getERC20TokenContract(token: address, parent: boolean = false) {
const web3 = parent ? this.web3Client.parentWeb3 : this.web3Client.web3
return new web3.eth.Contract(ChildERC20Artifact.abi, token)

ADD
src/common/transferWithSigABI.json
+[
+ {
+ "constant": false,
+ "inputs": [
+ {
+ "internalType": "bytes",
+ "name": "sig",
+ "type": "bytes"
+ },
+ {
+ "internalType": "uint256",
+ "name": "tokenId",
+ "type": "uint256"
+ },
+ {
+ "internalType": "bytes32",
+ "name": "data",
+ "type": "bytes32"
+ },
+ {
+ "internalType": "uint256",
+ "name": "expiration",
+ "type": "uint256"
+ },
+ {
+ "internalType": "address",
+ "name": "to",
+ "type": "address"
+ }
+ ],
+ "name": "transferWithSig",
+ "outputs": [
+ {
+ "internalType": "address",
+ "name": "",
+ "type": "address"
+ }
+ ],
+ "payable": false,
+ "stateMutability": "nonpayable",
+ "type": "function"
+ }
+]
\ No newline at end of file

MODIFY
src/index.ts
src/index.ts
@@ -195,6 +195,46 @@ export default class Matic extends ContractsBase {
return this.utils.signEIP712TypedData(typedData, wallet[options.from].privateKey)
}
+ async transferWithSignature(
+ token: address,
+ sig: string,
+ sellOrder: order,
+ buyOrder: order,
+ to: address,
+ options: SendOptions
+ ) {
+ if (!options.from) {
+ throw new Error('options.from is missing')
+ }
+ let web3Util = this.web3Client.web3.utils
+ let data = web3Util.soliditySha3(
+ {
+ t: 'bytes32',
+ v: sellOrder.orderId,
+ },
+ {
+ t: 'address',
+ v: buyOrder.token,
+ },
+ {
+ t: 'uint256',
+ v: buyOrder.amount,
+ }
+ )
+
+ const txObj = this.getTokenContractForTransferWithSig(token).methods.transferWithSig(
+ sig,
+ sellOrder.amount,
+ data,
+ sellOrder.expiry,
+ to
+ )
+
+ const _options = await this._fillOptions(options, txObj, this.web3Client.getMaticWeb3())
+
+ return this.web3Client.send(txObj, _options)
+ }
+
depositERC20ForUser(token: address, user: address, amount: BN | string, options?: SendOptions) {
if (options && (!options.from || !amount || !token)) {
throw new Error('options.from, token or amount is missing')

MODIFY
src/types/Common.ts
src/types/Common.ts
@@ -12,7 +12,7 @@ export declare interface SendOptions {
export declare interface order {
token: string
- amount: string | number
+ amount: string
expiry?: string | number
orderId?: string
spender?: string

new: users: add transferWithSignature method