fix plasma deposit
MODIFY
src/plasma/deposit_manager.ts
src/plasma/deposit_manager.ts
-import { BaseWeb3Client, BaseContract } from "../abstracts";
+import { BaseToken, Web3SideChainClient } from "../utils";
-export class DepositManager {
- contract: BaseContract;
+export class DepositManager extends BaseToken {
- constructor(private client_: BaseWeb3Client, address: string, abi) {
- this.contract = this.client_.getContract(
- address,
- abi
+ constructor(client: Web3SideChainClient, address: string) {
+ super(
+ {
+ isParent: true,
+ tokenAddress: address,
+ tokenContractName: "DepositManager"
+ },
+ client
);
}
+ get address() {
+ return this.contractParam.tokenAddress;
+ }
+
}
\ No newline at end of file

MODIFY
src/plasma/erc20.ts
src/plasma/erc20.ts
@@ -51,10 +51,11 @@ export class ERC20 extends BaseToken {
}
approve(amount: TYPE_AMOUNT, option: ITransactionOption = {}) {
+ this.checkForParent("approve");
return this.getContract().then(contract => {
const method = contract.method(
"approve",
- this.contracts_.depositManager.contract.address,
+ this.contracts_.depositManager.address,
Converter.toHex(amount)
);
return this.processWrite(method, option);
@@ -70,11 +71,12 @@ export class ERC20 extends BaseToken {
}
deposit(amount: TYPE_AMOUNT, userAddress: string, option: ITransactionOption = {}) {
- return this.getContract().then(tokenContract => {
- const contract = this.contracts_.depositManager.contract;
+ this.checkForParent("deposit");
+
+ return this.contracts_.depositManager.getContract().then(contract => {
const method = contract.method(
"depositERC20ForUser",
- tokenContract.address,
+ this.contractParam.tokenAddress,
userAddress,
Converter.toHex(amount)
);
@@ -83,6 +85,9 @@ export class ERC20 extends BaseToken {
}
withdrawStart(amount: TYPE_AMOUNT, option?: ITransactionOption) {
+ this.checkForChild("withdrawStart");
+
+
return this.getContract().then(tokenContract => {
const method = tokenContract.method(
"withdraw",

MODIFY
src/plasma/erc721.ts
src/plasma/erc721.ts
@@ -60,18 +60,18 @@ export class ERC721 extends BaseToken {
* @param tokenId
* @param options
*/
- safeDepositERC721(tokenId: number, options?: ITransactionOption) {
- return this.getContract().then(contract => {
- const method = contract.method(
- "safeTransferFrom",
- options.from,
- this.depositManager.contract.address,
- tokenId,
- );
+ // safeDepositERC721(tokenId: number, options?: ITransactionOption) {
+ // return this.getContract().then(contract => {
+ // const method = contract.method(
+ // "safeTransferFrom",
+ // options.from,
+ // this.depositManager.contract.address,
+ // tokenId,
+ // );
- return this.processWrite(method, options);
- });
- }
+ // return this.processWrite(method, options);
+ // });
+ // }
/**
* WRITE

MODIFY
src/plasma/ether.ts
src/plasma/ether.ts
@@ -30,12 +30,13 @@ export class Ether extends BaseToken {
}
deposit(amount: TYPE_AMOUNT, option: ITransactionOption = {}) {
- const contract = this.contracts_.depositManager.contract;
+ return this.contracts_.depositManager.getContract().then(contract => {
option.value = Converter.toHex(amount);
const method = contract.method(
"depositEther",
);
return this.processWrite(method, option);
+ });
}
transfer(amount: TYPE_AMOUNT, to: string, option: ITransactionOption = {}) {

MODIFY
src/plasma/index.ts
src/plasma/index.ts
@@ -48,7 +48,7 @@ export class PlasmaClient {
}
constructor(config: IPlasmaClientConfig) {
- const client = this.client_ = new Web3SideChainClient(config);
+ this.client_ = new Web3SideChainClient(config);
LOGGER.enableLog(config.log);
}
@@ -78,15 +78,13 @@ export class PlasmaClient {
client.config.registry,
);
- return this.client_.getABI("DepositManager").then(abi => {
this.depositManager = new DepositManager(
- client.parent,
- client.config.depositManager,
- abi
+ client,
+ client.config.depositManager
);
+
return this;
});
- });
}
ether(isParent?) {

MODIFY
src/pos/root_chain_manager.ts
src/pos/root_chain_manager.ts
@@ -30,7 +30,7 @@ export class RootChainManager extends BaseToken {
}
async exit(exitPayload: string, option: ITransactionOption) {
- this.method("exit", exitPayload).then(method => {
+ return this.method("exit", exitPayload).then(method => {
return this.processWrite(
method,
option

MODIFY
src/utils/base_token.ts
src/utils/base_token.ts
@@ -5,6 +5,7 @@ import { merge } from "../utils";
import { EXTRA_GAS_FOR_PROXY_CALL, LOGGER } from "../constant";
import { ContractWriteResult } from "../helpers";
import { promiseResolve } from "./promise_resolve";
+import { ERROR_TYPE } from "../enums";
export interface ITransactionConfigParam {
txConfig: ITransactionConfig;
@@ -177,4 +178,18 @@ export class BaseToken {
return txConfig;
}
+ protected checkForParent(methodName) {
+ if (!this.contractParam.isParent) {
+ this.client.logger.error(
+ ERROR_TYPE.AllowedOnRoot, methodName
+ ).throw();
+ }
+ }
+
+ protected checkForChild(methodName) {
+ if (this.contractParam.isParent) {
+ this.client.logger.error(ERROR_TYPE.AllowedOnChild, methodName).throw();
+ }
+ }
+
}
\ No newline at end of file

MODIFY
test/debug.js
test/debug.js
@@ -7,9 +7,10 @@ const from = user1.address;
const execute = async () => {
const privateKey = user1.privateKey;
- const mumbaiERC720 = pos.child.erc20;
- const goerliERC720 = pos.parent.erc20;
- const posClient = new POSClient({
+ const mumbaiERC720 = plasma.child.erc20;
+ const goerliERC720 = plasma.parent.erc20;
+
+ const client = new PlasmaClient({
network: 'testnet',
version: 'mumbai',
parent: {
@@ -27,19 +28,20 @@ const execute = async () => {
});
- await posClient.init();
+ await client.init();
console.log("init called");
- const mumbaiERC720Token = posClient.erc20(mumbaiERC720);
- const goerliERC720Token = posClient.erc20(goerliERC720, true);
+ const mumbaiERC720Token = client.erc20(mumbaiERC720);
+ const goerliERC720Token = client.erc20(goerliERC720, true);
- const balance = await mumbaiERC720Token.getBalance(from);
- return console.log("balance", balance);
+ // const balance = await mumbaiERC720Token.getBalance(from);
+ // return console.log("balance", balance);
- // const tx = await goerliERC720Token.deposit(10, from);
- // console.log("txHash", await tx.getTransactionHash());
- // console.log("txReceipt", await tx.getReceipt());
+ const tx = await goerliERC720Token.approve(10, from);
+ // // const tx = await goerliERC720Token.withdrawExit('0x454f159823351b24ce0e675e7b308cc8c7ba39e175059a4d2b8f9507c17b5133');
+ console.log("txHash", await tx.getTransactionHash());
+ console.log("txReceipt", await tx.getReceipt());
// const tx = await mumbaiERC720Token.withdrawStart(
// 10,

fix plasma deposit