chg: update readme to add transferWithSig functions
MODIFY
README.md
README.md
@@ -11,6 +11,7 @@ We will be improving this library to make all features available like Plasma Fas
### Installation
#### NPM
+
---
```bash
@@ -204,6 +205,7 @@ Please write to info@matic.network to request TEST tokens for development purpos
- <a href="#startExitForMintableBurntToken"><code>matic.<b>withdrawManager.startExitForMintableBurntToken()</b></code></a>
- <a href="#startExitForMetadataMintableBurntToken"><code>matic.<b>withdrawManager.startExitForMetadataMintableBurntToken()</b></code></a>
+
---
<a name="initialize"></a>
@@ -213,11 +215,10 @@ Please write to info@matic.network to request TEST tokens for development purpos
Creates Matic SDK instance with give options. It returns a MaticSDK object.
```js
-import Matic from "maticjs"
+import Matic from 'maticjs'
const matic = new Matic(options)
matic.initialize()
-
```
- `options` is simple Javascript `object` which can have following fields:
@@ -233,12 +234,12 @@ matic.initialize()
- `registry` must be valid Ethereum contract address.
- `withdrawManager` must be valid Ethereum contract address.
- `depositManager` must be valid Ethereum contract address.
----
+---
---
-<a name="balanceOfERC20"></a>
+<a name="balanceOfERC20"></a>
#### matic.balanceOfERC20(userAddress, token, options)
@@ -255,17 +256,17 @@ Example:
```js
matic
- .balanceOfERC20("0xABc578455...", "0x5E9c4ccB05...", {
- from: "0xABc578455..."
+ .balanceOfERC20('0xABc578455...', '0x5E9c4ccB05...', {
+ from: '0xABc578455...',
})
.then(balance => {
- console.log("balance", balance)
+ console.log('balance', balance)
})
```
---
-<a name="balanceOfERC721"></a>
+<a name="balanceOfERC721"></a>
#### matic.balanceOfERC721(userAddress, token, options)
@@ -282,17 +283,17 @@ Example:
```js
matic
- .balanceOfERC721("0xABc578455...", "0x5E9c4ccB05...", {
- from: "0xABc578455..."
+ .balanceOfERC721('0xABc578455...', '0x5E9c4ccB05...', {
+ from: '0xABc578455...',
})
.then(balance => {
- console.log("balance", balance)
+ console.log('balance', balance)
})
```
---
-<a name="tokenOfOwnerByIndexERC721"></a>
+<a name="tokenOfOwnerByIndexERC721"></a>
#### matic.tokenOfOwnerByIndexERC721(userAddress, token, index, options)
@@ -302,18 +303,17 @@ get ERC721 tokenId at `index` for `token` and for `address`.
- `userAddress` must be valid user address
- `index` index of tokenId
-
This returns matic `tokenId`.
Example:
```js
matic
- .tokenOfOwnerByIndexERC721("0xfeb14b...", "21", 0, {
- from: "0xABc578455..."
+ .tokenOfOwnerByIndexERC721('0xfeb14b...', '21', 0, {
+ from: '0xABc578455...',
})
.then(tokenID => {
- console.log("Token ID", tokenID)
+ console.log('Token ID', tokenID)
})
```
@@ -322,6 +322,7 @@ matic
#### matic.depositEthers(amount, options)
Deposit `options.value`
+
- `amount` must be token amount in wei (string, not in Number)
- `options` see [more infomation here](#approveERC20TokensForDeposit).
- `from` must be valid account address(required)
@@ -333,11 +334,12 @@ Example:
```js
matic.depositEthers(amount, {
- from: '0xABc578455...'
+ from: '0xABc578455...',
})
```
---
+
<a name="approveERC20TokensForDeposit"></a>
#### matic.approveERC20TokensForDeposit(token, amount, options)
@@ -357,9 +359,8 @@ This returns `Promise` object, which will be fulfilled when transaction gets con
Example:
```js
-matic
- .approveERC20TokensForDeposit("0x718Ca123...", "1000000000000000000", {
- from: "0xABc578455..."
+matic.approveERC20TokensForDeposit('0x718Ca123...', '1000000000000000000', {
+ from: '0xABc578455...',
})
```
@@ -406,9 +407,8 @@ This returns `Promise` object, which will be fulfilled when transaction gets con
Example:
```js
-
matic.safeDepositERC721Tokens('0x718Ca123...', '70000000000', {
- from: '0xABc578455...'
+ from: '0xABc578455...',
})
```
@@ -490,9 +490,8 @@ This returns `Promise` object, which will be fulfilled when transaction gets con
Example:
```js
-matic
- .startWithdraw("0x718Ca123...", "1000000000000000000", {
- from: "0xABc578455..."
+matic.startWithdraw('0x718Ca123...', '1000000000000000000', {
+ from: '0xABc578455...',
})
```
@@ -514,9 +513,8 @@ This returns `Promise` object, which will be fulfilled when transaction gets con
Example:
```js
-matic
- .startWithdrawForNFT("0x718Ca123...", "1000000000000000000", {
- from: "0xABc578455..."
+matic.startWithdrawForNFT('0x718Ca123...', '1000000000000000000', {
+ from: '0xABc578455...',
})
```
@@ -536,8 +534,8 @@ This returns `Promise` object, which will be fulfilled when transaction gets con
Example:
```js
-matic.withdraw("0xabcd...789", {
- from: "0xABc578455..."
+matic.withdraw('0xabcd...789', {
+ from: '0xABc578455...',
})
```
@@ -558,13 +556,45 @@ This returns `Promise` object, which will be fulfilled when transaction gets con
Example:
```js
-matic.withdrawNFT("0xabcd...789", {
- from: "0xABc578455..."
+matic.withdrawNFT('0xabcd...789', {
+ from: '0xABc578455...',
})
```
---
+#### Execute Signatured Order
+
+#### matic.getTransferSignature
+
+Off-chain signature generation for [transferWithSig](https://github.com/maticnetwork/contracts/blob/a9b77252ece25adcd3f74443411821883bb970e6/contracts/child/BaseERC20.sol#L35) function call
+
+```javascript
+const sig = await matic.getTransferSignature(toSell, toBuy, {
+ from: tokenOwner,
+})
+```
+
+#### matic.transferWithSignature
+
+Executes [transferWithSig](https://github.com/maticnetwork/contracts/blob/a9b77252ece25adcd3f74443411821883bb970e6/contracts/child/BaseERC20.sol#L35) on child token (erc20/721). Takes input as signature generated from `matic.getTransferSignature`
+
+```javascript
+// transfers `toSell.token` from `tokenOwner` to `orderFiller`
+
+const tx = await matic.transferWithSignature(
+ sig, // signature with the intent to buy tokens
+ toSell, // sell order
+ toBuy, // buy order
+ orderFiller, // order fulfiller
+ {
+ from: spender, // approved spender
+ }
+)
+```
+
+---
+
<a name="processExits"></a>
#### matic.processExits(rootTokenAddress, options)
@@ -580,10 +610,11 @@ This returns `Promise` object, which will be fulfilled when transaction gets con
Example:
```js
-matic.processExits("0xabcd...789", {
- from: "0xABc578455..."
+matic.processExits('0xabcd...789', {
+ from: '0xABc578455...',
})
```
+
---
#### **WithdrawManager**
@@ -591,6 +622,7 @@ matic.processExits("0xabcd...789", {
<a name="startExitForMintableBurntToken"></a>
#### matic.withdrawManager.startExitForMintableBurntToken(burnTxHash, predicate: address, options)
+
```
/**
* Start an exit for a token that was minted and burnt on the side chain
@@ -599,17 +631,20 @@ matic.processExits("0xabcd...789", {
* @param predicate address of MintableERC721Predicate
*/
```
+
See [MintableERC721Predicate.startExitForMintableBurntToken](https://github.com/maticnetwork/contracts/blob/e2cb462b8487921463090b0bdcdd7433db14252b/contracts/root/predicates/MintableERC721Predicate.sol#L31)
```
const burn = await this.maticClient.startWithdrawForNFT(childErc721.address, tokenId)
await this.maticClient.withdrawManager.startExitForMintableBurntToken(burn.transactionHash, predicate.address)
```
+
---
<a name="startExitForMetadataMintableBurntToken"></a>
#### matic.withdrawManager.startExitForMintableBurntToken(burnTxHash, predicate: address, options)
+
```
/**
* Start an exit for a token with metadata (token uri) that was minted and burnt on the side chain
@@ -618,12 +653,14 @@ await this.maticClient.withdrawManager.startExitForMintableBurntToken(burn.trans
* @param predicate address of MintableERC721Predicate
*/
```
+
See [MintableERC721Predicate.startExitForMetadataMintableBurntToken](https://github.com/maticnetwork/contracts/blob/e2cb462b8487921463090b0bdcdd7433db14252b/contracts/root/predicates/MintableERC721Predicate.sol#L66)
```
const burn = await this.maticClient.startWithdrawForNFT(childErc721.address, tokenId)
await this.maticClient.withdrawManager.startExitForMetadataMintableBurntToken(burn.transactionHash, predicate.address)
```
+
---
### Support

chg: update readme to add transferWithSig functions