allow to specify spender address in approve and allowance
MODIFY
.github/workflows/test.yml
.github/workflows/test.yml
@@ -45,4 +45,4 @@ jobs:
- name: TEST
run: |
# echo "$USER1_FROM",
- npm run test
+ npm run build:test

MODIFY
package.json
package.json
{
"name": "@maticnetwork/maticjs",
- "version": "3.2.1",
+ "version": "3.2.2",
"description": "Javascript developer library for interacting with Matic Network",
"main": "dist/npm.export.js",
"types": "dist/ts/index.d.ts",
"prepublishOnly": "npm run deploy",
"lint": "tslint src/**/*.ts",
"lint:fix": "tslint src/**/*.ts --fix",
- "test": "npm run build:pack && cd test && npm run install:lib:test",
+ "build:test": "npm run build:pack && npm run test",
+ "test": "cd test && npm run install:lib:test",
"debug": "npm run build:pack && cd test && npm run install:lib:debug",
"testrpc": "ganache-cli --mnemonic 'clock radar mass judge dismiss just intact mind resemble fringe diary casino' --gasLimit 13000000",
"install:example": "cd examples && npm i ../maticnetwork-maticjs-3.0.0-beta.2.tgz --no-save"

ADD
src/interfaces/allowance_transaction_option.ts
+import { ITransactionOption } from "./transaction_option";
+
+export interface IAllowanceTransactionOption extends ITransactionOption {
+
+ /**
+ * address of spender
+ *
+ * **spender** - third-party user or a smart contract which can transfer your token on your behalf.
+ *
+ * @type {string}
+ * @memberof IAllowanceTransactionOption
+ */
+ spenderAddress?: string;
+}
\ No newline at end of file

ADD
src/interfaces/approve_transaction_option.ts
+import { ITransactionOption } from "./transaction_option";
+
+export interface IApproveTransactionOption extends ITransactionOption {
+
+ /**
+ * address of spender
+ *
+ * **spender** - third-party user or a smart contract which can transfer your token on your behalf.
+ *
+ * @type {string}
+ * @memberof IAllowanceTransactionOption
+ */
+ spenderAddress?: string;
+}
\ No newline at end of file

MODIFY
src/interfaces/index.ts
src/interfaces/index.ts
@@ -17,3 +17,5 @@ export * from "./base_client_config";
export * from "./error";
export * from "./pos_contracts";
export * from "./root_block_info";
+export * from "./allowance_transaction_option";
+export * from "./approve_transaction_option";
\ No newline at end of file

MODIFY
src/pos/erc20.ts
src/pos/erc20.ts
@@ -3,12 +3,11 @@ import { Converter, Web3SideChainClient } from "../utils";
import { POSToken } from "./pos_token";
import { TYPE_AMOUNT } from "../types";
import { Log_Event_Signature } from "../enums";
-import { IPOSClientConfig, MAX_AMOUNT } from "..";
+import { IAllowanceTransactionOption, IApproveTransactionOption, IPOSClientConfig, MAX_AMOUNT, promiseResolve } from "..";
import { IPOSContracts } from "../interfaces/pos_contracts";
export class ERC20 extends POSToken {
-
constructor(
tokenAddress: string,
isParent: boolean,
@@ -41,9 +40,12 @@ export class ERC20 extends POSToken {
* @returns
* @memberof ERC20
*/
- getAllowance(userAddress: string, option?: ITransactionOption) {
+ getAllowance(userAddress: string, option: IAllowanceTransactionOption = {}) {
+ const spenderAddress = option.spenderAddress;
+ const predicatePromise = spenderAddress ?
+ this.getPredicateAddress() : promiseResolve(spenderAddress);
- return Promise.all([this.getPredicateAddress(), this.getContract()]).then(result => {
+ return Promise.all([predicatePromise, this.getContract()]).then(result => {
const [predicateAddress, contract] = result;
const method = contract.method(
"allowance",
@@ -54,10 +56,12 @@ export class ERC20 extends POSToken {
});
}
- approve(amount: TYPE_AMOUNT, option?: ITransactionOption) {
- this.checkForRoot("approve");
+ approve(amount: TYPE_AMOUNT, option?: IApproveTransactionOption) {
+ const spenderAddress = option.spenderAddress;
+ const predicatePromise = spenderAddress ?
+ this.getPredicateAddress() : promiseResolve(spenderAddress);
- return Promise.all([this.getPredicateAddress(), this.getContract()]).then(result => {
+ return Promise.all([predicatePromise, this.getContract()]).then(result => {
const [predicateAddress, contract] = result;
const method = contract.method(
"approve",
@@ -87,7 +91,6 @@ export class ERC20 extends POSToken {
deposit(amount: TYPE_AMOUNT, userAddress: string, option?: ITransactionOption) {
this.checkForRoot("deposit");
-
const amountInABI = this.client.parent.encodeParameters(
[Converter.toHex(amount)],
['uint256'],

MODIFY
test/specs/erc721.spec.ts
test/specs/erc721.spec.ts
@@ -47,11 +47,11 @@ describe('ERC721', () => {
expect(isExited).equal(true);
})
- // it('isDeposited for deposit many', async () => {
- // const depositTxhash = '0x2ae0f5073e0c0f96f622268ef8bc61ecec7349ffc97c61412e4f5cc157cb418e';
- // const isExited = await erc721Parent.isDeposited(depositTxhash);
- // expect(isExited).equal(true);
- // })
+ it('isDeposited for deposit many', async () => {
+ const depositTxhash = '0x2ae0f5073e0c0f96f622268ef8bc61ecec7349ffc97c61412e4f5cc157cb418e';
+ const isExited = await posClient.isDeposited(depositTxhash);
+ expect(isExited).equal(true);
+ })
it('transfer return tx', async () => {
const allTokensFrom = await erc721Child.getAllTokens(from);
@@ -123,10 +123,11 @@ describe('ERC721', () => {
it('withdrawExitWithMetaData return tx', async () => {
const txHash = `0x0600732ea675d8e63a4fed0a267a261a9e0d1728e805fda4884adb7c75454e7b`
- const result = await erc721Child.withdrawExitWithMetaData(txHash, {
+ const result = await erc721Parent.withdrawExitWithMetaData(txHash, {
returnTransaction: true
});
- expect(result['to'].toLowerCase()).equal(erc721.child.toLowerCase());
+ const rootChainManager = await abiManager.getConfig("Main.POSContracts.RootChainManagerProxy")
+ expect(result['to'].toLowerCase()).equal(rootChainManager.toLowerCase());
})
it('transfer write', async () => {

allow to specify spender address in approve and allowance