add abstract for BaseBigNumber
ADD
src/abstracts/base_big_number.ts
+export abstract class BaseBigNumber {
+ static isBN(value): boolean {
+ throw new Error("not implemented");
+ }
+
+ abstract toString(): string;
+ abstract toNumber(): number;
+ abstract toBuffer(): Buffer;
+ abstract add(value: BaseBigNumber): BaseBigNumber;
+ abstract sub(value: BaseBigNumber): BaseBigNumber;
+ abstract mul(value: BaseBigNumber): BaseBigNumber;
+ abstract div(value: BaseBigNumber): BaseBigNumber;
+
+ abstract lte(value: BaseBigNumber): boolean;
+ abstract lt(value: BaseBigNumber): boolean;
+ abstract gte(value: BaseBigNumber): boolean;
+ abstract gt(value: BaseBigNumber): boolean;
+ abstract eq(value: BaseBigNumber): boolean;
+}
\ No newline at end of file

MODIFY
src/abstracts/base_web3_client.ts
src/abstracts/base_web3_client.ts
-import BN from "bn.js";
import { BaseContract } from "../abstracts";
import { ITransactionConfig, ITransactionReceipt, ITransactionData, IBlock, IBlockWithTransaction, IJsonRpcRequestPayload, IJsonRpcResponse, ITransactionWriteResult } from "../interfaces";
import { Logger } from "../utils";

MODIFY
src/abstracts/index.ts
src/abstracts/index.ts
export * from "./contract_method";
export * from "./base_web3_client";
export * from "./base_contract";
+export * from "./base_big_number";
\ No newline at end of file

MODIFY
src/constant.ts
src/constant.ts
-import BN from "bn.js";
+import { utils } from "./utils"
-export const BIG_ONE = new BN(1)
-export const BIG_TWO = new BN(2)
-export const CHECKPOINT_INTERVAL = new BN(10000)
+export const BIG_ONE = new utils.BN(1)
+export const BIG_TWO = new utils.BN(2)
+export const CHECKPOINT_INTERVAL = new utils.BN(10000)
export const MAX_AMOUNT = '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'

ADD
src/implementation/bn.ts
+import BN from "bn.js";
+import { BaseBigNumber } from "../abstracts";
+
+export class MaticBigNumber extends BaseBigNumber {
+ private bn_: BN;
+
+ constructor(value) {
+ super();
+ this.bn_ = new BN(value);
+
+ // this.bn_.toString()
+ }
+
+ static isBN(value) {
+ if (value instanceof MaticBigNumber) {
+ return true;
+ }
+ return BN.isBN(value);
+ }
+
+ toString(base?) {
+ return this.bn_.toString(base);
+ }
+
+ toNumber() {
+ return this.bn_.toNumber();
+ }
+
+ toBuffer(base?) {
+ return this.bn_.toBuffer();
+ }
+
+ // static from(value) {
+ // return new MaticBigNumber(value);
+ // }
+
+ add(value: BaseBigNumber) {
+ const bn = this.bn_.add(
+ new BN(value.toString())
+ );
+ return new MaticBigNumber(bn);
+ }
+
+ sub(value: BaseBigNumber) {
+ const bn = this.bn_.sub(
+ new BN(value.toString())
+ );
+ return new MaticBigNumber(bn);
+ }
+
+ mul(value: BaseBigNumber) {
+ const bn = this.bn_.mul(
+ new BN(value.toString())
+ );
+ return new MaticBigNumber(bn);
+ }
+
+ div(value: BaseBigNumber) {
+ const bn = this.bn_.div(
+ new BN(value.toString())
+ );
+ return new MaticBigNumber(bn);
+ }
+
+ lte(value: BaseBigNumber) {
+ return this.bn_.lte(
+ new BN(value.toString())
+ );
+ }
+
+ lt(value: BaseBigNumber) {
+ return this.bn_.lt(
+ new BN(value.toString())
+ );
+ }
+
+ gte(value: BaseBigNumber) {
+ return this.bn_.gte(
+ new BN(value.toString())
+ );
+ }
+
+ gt(value: BaseBigNumber) {
+ return this.bn_.gt(
+ new BN(value.toString())
+ );
+ }
+
+ eq(value: BaseBigNumber) {
+ return this.bn_.eq(
+ new BN(value.toString())
+ );
+ }
+}
\ No newline at end of file

ADD
src/implementation/index.ts
+export * from "./bn";
\ No newline at end of file

MODIFY
src/interfaces/transaction_config.ts
src/interfaces/transaction_config.ts
-import BN from "bn.js";
+import { BaseBigNumber } from "../abstracts";
export interface ITransactionConfig {
from?: string;
to?: string;
- value?: number | string | BN;
+ value?: number | string | BaseBigNumber;
gasLimit?: number | string;
- gasPrice?: number | string | BN;
+ gasPrice?: number | string | BaseBigNumber;
data?: string;
nonce?: number;
chainId?: number;

MODIFY
src/pos/exit_util.ts
src/pos/exit_util.ts
import { RootChain } from "./root_chain";
import { Converter, ProofUtil, Web3SideChainClient } from "../utils";
-import BN from "bn.js";
import ethUtils from "ethereumjs-util";
import { IBlockWithTransaction, ITransactionReceipt } from "../interfaces";
import { service } from "../services";
-import { BaseWeb3Client } from "../abstracts";
+import { BaseBigNumber, BaseWeb3Client } from "../abstracts";
import { ErrorHelper } from "../utils/error_helper";
-import { ERROR_TYPE, IBaseClientConfig } from "..";
+import { ERROR_TYPE, IBaseClientConfig, utils } from "..";
interface IChainBlockInfo {
lastChildBlock: string;
@@ -16,7 +15,7 @@ interface IChainBlockInfo {
interface IRootBlockInfo {
start: string;
end: string;
- blockNumber: BN;
+ blockNumber: BaseBigNumber;
}
export class ExitUtil {
@@ -80,7 +79,9 @@ export class ExitUtil {
private isCheckPointed_(data: IChainBlockInfo) {
// lastchild block is greater equal to transacton block number;
- return new BN(data.lastChildBlock).gte(new BN(data.txBlockNumber));
+ return new utils.BN(data.lastChildBlock).gte(
+ new utils.BN(data.txBlockNumber)
+ );
}
isCheckPointed(burnTxHash: string) {
@@ -95,7 +96,7 @@ export class ExitUtil {
private getRootBlockInfo(txBlockNumber: number) {
// find in which block child was included in parent
- let rootBlockNumber: BN;
+ let rootBlockNumber: BaseBigNumber;
return this.rootChain.findRootBlockFromChild(
txBlockNumber
).then(blockNumber => {
@@ -210,7 +211,7 @@ export class ExitUtil {
);
return this.encodePayload_(
- rootBlockInfo.blockNumber,
+ rootBlockInfo.blockNumber.toNumber(),
blockProof,
txBlockNumber,
block.timestamp,

MODIFY
src/pos/root_chain.ts
src/pos/root_chain.ts
-import { BaseToken, Web3SideChainClient } from "../utils";
+import { BaseToken, utils, Web3SideChainClient } from "../utils";
import { TYPE_AMOUNT } from "../types";
-import BN from "bn.js";
import { BIG_ONE, CHECKPOINT_INTERVAL, BIG_TWO } from "../constant";
import { IPOSClientConfig, ITransactionOption } from "../interfaces";
+import { BaseBigNumber } from "..";
export class RootChain extends BaseToken<IPOSClientConfig> {
@@ -26,15 +26,15 @@ export class RootChain extends BaseToken<IPOSClientConfig> {
});
}
- async findRootBlockFromChild(childBlockNumber: TYPE_AMOUNT): Promise<BN> {
- childBlockNumber = new BN(childBlockNumber);
+ async findRootBlockFromChild(childBlockNumber: TYPE_AMOUNT): Promise<BaseBigNumber> {
+ childBlockNumber = new utils.BN(childBlockNumber);
// first checkpoint id = start * 10000
let start = BIG_ONE;
// last checkpoint id = end * 10000
const method = await this.method("currentHeaderBlock");
const currentHeaderBlock = await method.read<string>();
- let end = new BN(currentHeaderBlock).div(
+ let end = new utils.BN(currentHeaderBlock).div(
CHECKPOINT_INTERVAL
);
@@ -52,8 +52,8 @@ export class RootChain extends BaseToken<IPOSClientConfig> {
);
const headerBlock = await headerBlocksMethod.read<{ start: number, end: number }>();
- const headerStart = new BN(headerBlock.start);
- const headerEnd = new BN(headerBlock.end);
+ const headerStart = new utils.BN(headerBlock.start);
+ const headerEnd = new utils.BN(headerBlock.end);
if (headerStart.lte(childBlockNumber) && childBlockNumber.lte(headerEnd)) {
// if childBlockNumber is between the upper and lower bounds of the headerBlock, we found our answer

MODIFY
src/services/network_service.ts
src/services/network_service.ts
+import { BaseBigNumber } from "..";
import { HttpRequest } from "../utils";
-import BN from "bn.js";
export class NetworkService {
httpRequest: HttpRequest;
@@ -19,7 +19,7 @@ export class NetworkService {
start: string;
end: string;
headerBlockNumber: string;
- blockNumber: BN
+ blockNumber: BaseBigNumber
}>(url).then(result => {
result['blockNumber'] = result.headerBlockNumber as any;
return result;

MODIFY
src/types/index.ts
src/types/index.ts
-import BN from "bn.js";
+import { BaseBigNumber } from "..";
// export * from "./side_chain_client_option";
-export type TYPE_AMOUNT = BN | string | number;
\ No newline at end of file
+export type TYPE_AMOUNT = BaseBigNumber | string | number;
\ No newline at end of file

MODIFY
src/utils/bridge_client.ts
src/utils/bridge_client.ts
-import BN from "bn.js";
import { Web3SideChainClient } from "../utils";
import { ExitUtil } from "../pos";
import { BaseToken, utils } from "..";
@@ -51,8 +50,8 @@ export class BridgeClient<T> {
throw new Error("StateSynced event not found");
}
const rootStateId = client.child.decodeParameters(targetLog.topics[1], ['uint256'])[0];
- const rootStateIdBN = utils.isBN(rootStateId) ? rootStateId : new BN(rootStateId);
- return new BN(lastStateId).gte(
+ const rootStateIdBN = utils.BN.isBN(rootStateId) ? rootStateId : new utils.BN(rootStateId);
+ return new utils.BN(lastStateId).gte(
rootStateIdBN
);
});

MODIFY
src/utils/converter.ts
src/utils/converter.ts
-import BN from "bn.js";
+import { BaseBigNumber } from "../abstracts";
import { utils } from "../utils";
export class Converter {
- static toHex(amount: BN | string | number) {
+ static toHex(amount: BaseBigNumber | string | number) {
const dataType = typeof amount;
if (dataType === 'number') {
- amount = new BN(amount);
+ amount = new utils.BN(amount);
} else if (dataType === 'string') {
if ((amount as string).slice(0, 2) === '0x') {
return amount;
}
- amount = new BN(amount);
+ amount = new utils.BN(amount);
}
- if (utils.isBN(amount)) {
+ if (utils.BN.isBN(amount)) {
return '0x' + amount.toString(16);
}
else {

MODIFY
src/utils/index.ts
src/utils/index.ts
-import BN from "bn.js";
import { BaseWeb3Client, Converter, TYPE_AMOUNT } from "..";
+import { MaticBigNumber } from "../implementation";
export * from "./use";
export * from "./event_bus";
@@ -21,7 +21,5 @@ export * from "./abi_manager";
export const utils = {
converter: Converter,
Web3Client: BaseWeb3Client,
- isBN(value) {
- return BN.isBN(value);
- }
+ BN: MaticBigNumber
};
\ No newline at end of file

MODIFY
test/debug.js
test/debug.js
@@ -43,29 +43,35 @@ const execute = async () => {
// return console.log(await client.isDeposited('0xc67599f5c967f2040786d5924ec55d37bf943c009bdd23f3b50e5ae66efde258'));
- const balance = await mumbaiERC20Token.getBalance(
- from
- );
- return console.log("balance", balance);
+ // const balance = await mumbaiERC20Token.getBalance(
+ // from
+ // );
+ // return console.log("balance", balance);
// const tokens = await goerliERC721Token.getAllTokens(
// from
// );
// return console.log("tokens", tokens);
- const tx = await goerliERC721Token.approveAll({
- maxPriorityFeePerGas: 2000000000,
+ // const tx = await goerliERC721Token.approveAll({
+ // maxPriorityFeePerGas: 2000000000,
// returnTransaction: true
- });
+ // });
// const tx = await goerliERC721Token.depositMany(['70362948865848051982628883253610138761681237831617060123833093242173388773544'], from, {
// returnTransaction: true
// });
+ setProofApi("https://apis.matic.network")
+ const tx = await goerliERC20Token.withdrawExitFaster(
+ '0x1c20c41b9d97d1026aa456a21f13725df63edec1b1f43aacb180ebcc6340a2d3', {
+ returnTransaction: true
+ });
+
console.log('tx', tx);
// // setProofApi("https://apis.matic.network")
// // const tx = await goerliERC20Token.withdrawExit('0xd6f7f4c6052611761946519076de28fbd091693af974e7d4abc1b17fd7926fd7');
- console.log("txHash", await tx.getTransactionHash());
- console.log("txReceipt", await tx.getReceipt());
+ // console.log("txHash", await tx.getTransactionHash());
+ // console.log("txReceipt", await tx.getReceipt());
//txhash to plasma exit - 0x63aa095e0d6ee8698399b871daa202eb5522933e2d94c5929cf0fb86b6b0c628
const tokenId = '60399350241383852757821046101235634991156913804166740995010931519407953501076'

add abstract for BaseBigNumber