implement exiterc20 legacy
ADD
src/enums/index.ts
+export * from "./log_event_signature";
\ No newline at end of file

ADD
src/enums/log_event_signature.ts
+export enum Log_Event_Signature {
+ Erc20Transfer = '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef'
+}
\ No newline at end of file

MODIFY
src/model/base_token.ts
src/model/base_token.ts
@@ -19,8 +19,8 @@ export class BaseToken {
contract: BaseContract;
constructor(
- public contractParam: IContractInitParam,
- public client: Web3SideChainClient,
+ protected contractParam: IContractInitParam,
+ protected client: Web3SideChainClient,
) {
this.contract = this.getContract(contractParam);
}
@@ -31,7 +31,7 @@ export class BaseToken {
txConfig: option,
isWrite: true,
method,
- isParent: true
+ isParent: this.contractParam.isParent
}).then(config => {
if (option.returnTransaction) {
return merge(config, {
@@ -47,21 +47,21 @@ export class BaseToken {
});
}
- getContract({ isParent, tokenAddress, abi }: IContractInitParam) {
+ protected getContract({ isParent, tokenAddress, abi }: IContractInitParam) {
const client = isParent ? this.client.parent.client :
this.client.child.client;
return client.getContract(tokenAddress, abi);
}
- get parentDefaultConfig() {
+ protected get parentDefaultConfig() {
return this.client.config.parent.defaultConfig;
}
- get childDefaultConfig() {
+ protected get childDefaultConfig() {
return this.client.config.child.defaultConfig;
}
- createTransactionConfig = async ({ txConfig, method, isParent, isWrite }: ITransactionConfigParam) => {
+ protected createTransactionConfig = async ({ txConfig, method, isParent, isWrite }: ITransactionConfigParam) => {
txConfig = Object.assign(this.parentDefaultConfig, txConfig || {});
const client = isParent ? this.client.parent.client :
this.client.child.client;

MODIFY
src/pos/erc20.ts
src/pos/erc20.ts
@@ -5,6 +5,8 @@ import { RootChainManager } from "./root_chain_manager";
import { formatAmount } from "../utils";
import { POSToken } from "./pos_token";
import { TYPE_AMOUNT } from "../types";
+import { ExitManager } from "./exit_manager";
+import { Log_Event_Signature } from "../enums";
export class ERC20 extends POSToken {
@@ -13,17 +15,16 @@ export class ERC20 extends POSToken {
tokenAddress: string,
isParent: boolean,
client: Web3SideChainClient,
- rootChainManager: RootChainManager
+ rootChainManager: RootChainManager,
+ exitManager: ExitManager
) {
super({
isParent,
tokenAddress,
abi: client.getABI('ChildERC20', 'pos')
- }, client, rootChainManager);
+ }, client, rootChainManager, exitManager);
}
-
-
getBalance(userAddress: string, option?: ITransactionOption) {
const contract = this.contract;
const method = contract.method(
@@ -75,7 +76,23 @@ export class ERC20 extends POSToken {
return this.processWrite(method, option);
}
+ /**
+ * complete withdraw process after checkpoint has been submitted for the block containing burn tx.
+ *
+ * @param {string} burnTransactionHash
+ * @param {ITransactionOption} [option]
+ * @returns
+ * @memberof ERC20
+ */
withdrawExit(burnTransactionHash: string, option?: ITransactionOption) {
+ return this.exitManager.exit(
+ burnTransactionHash,
+ Log_Event_Signature.Erc20Transfer,
+ option
+ );
+ }
+ withdrawExitFaster(burnTransactionHash: string, option?: ITransactionOption) {
+ // this.exitManager.
}
}
\ No newline at end of file

MODIFY
src/pos/exit_manager.ts
src/pos/exit_manager.ts
@@ -5,15 +5,33 @@ import { LOGGER } from "../constant";
import assert from "assert";
import BN from "bn.js";
import ethUtils from "ethereumjs-util";
+import { ITransactionOption } from "src/interfaces";
export class ExitManager {
private maticClient_: BaseWeb3Client;
rootChainManager: RootChainManager;
- constructor(childClient: BaseWeb3Client, rootChainManager: RootChainManager) {
- this.maticClient_ = childClient;
+ requestConcurrency: number;
+
+ constructor(maticClient: BaseWeb3Client, rootChainManager: RootChainManager, requestConcurrency: number) {
+ this.maticClient_ = maticClient;
this.rootChainManager = rootChainManager;
+ this.requestConcurrency = requestConcurrency;
+ }
+
+ async exit(burnTxHash: string, logSignature: string, option: ITransactionOption) {
+ const payload = await this.buildPayloadForExit(
+ burnTxHash,
+ logSignature,
+ this.requestConcurrency
+ );
+ const method = this.rootChainManager.method("exit", payload);
+
+ return this.rootChainManager['processWrite'](
+ method,
+ option
+ );
}
async buildPayloadForExit(burnTxHash: string, logEventSig: string, requestConcurrency?) {

MODIFY
src/pos/index.ts
src/pos/index.ts
@@ -28,14 +28,14 @@ export class POSClient {
);
this.rootChainManager = new RootChainManager(
- this.client_.parent.client,
+ this.client_,
config.rootChainManager,
- this.client_.getABI('RootChainManager', 'pos')
);
this.exitManager = new ExitManager(
this.client_.child.client,
- this.rootChainManager
+ this.rootChainManager,
+ null
);
LOGGER.enableLog(config.log);
@@ -46,7 +46,8 @@ export class POSClient {
tokenAddress,
isParent,
this.client_,
- this.rootChainManager
+ this.rootChainManager,
+ this.exitManager
);
}
}
\ No newline at end of file

MODIFY
src/pos/pos_token.ts
src/pos/pos_token.ts
import { BaseToken, Web3SideChainClient } from "../model";
import { ITransactionOption, IContractInitParam } from "../interfaces";
import { RootChainManager } from "./root_chain_manager";
+import { ExitManager } from "./exit_manager";
export class POSToken extends BaseToken {
@@ -9,7 +10,8 @@ export class POSToken extends BaseToken {
constructor(
contractParam: IContractInitParam,
client: Web3SideChainClient,
- public rootChainManager: RootChainManager
+ protected rootChainManager: RootChainManager,
+ protected exitManager: ExitManager
) {
super(contractParam, client);
}

MODIFY
src/pos/root_chain_manager.ts
src/pos/root_chain_manager.ts
-import { BaseContract, BaseWeb3Client } from "../model";
+import { BaseContract, BaseWeb3Client, BaseToken, Web3SideChainClient } from "../model";
import { TYPE_AMOUNT } from "../types";
import BN from "bn.js";
import { BIG_ONE, CHECKPOINT_INTERVAL, BIG_TWO, LOGGER } from "../constant";
-export class RootChainManager {
+export class RootChainManager extends BaseToken {
- contract: BaseContract;
-
- constructor(private client_: BaseWeb3Client, address: string, abi) {
- this.contract = this.client_.getContract(
- address,
- abi
- );
+ constructor(client_: Web3SideChainClient, address: string) {
+ super({
+ tokenAddress: address,
+ abi: client_.getABI('RootChainManager', 'pos'),
+ isParent: true
+ }, client_);
}
method(methodName: string, ...args) {

implement exiterc20 legacy