use BN instead of int
MODIFY
dist/index.js
dist/index.js
@@ -52,6 +52,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
+var bn_js_1 = __importDefault(require("bn.js"));
var DepositManager_1 = __importDefault(require("./root/DepositManager"));
var RootChain_1 = __importDefault(require("./root/RootChain"));
var Registry_1 = __importDefault(require("./root/Registry"));
@@ -85,7 +86,9 @@ var Matic = /** @class */ (function (_super) {
if (options && (!token || !userAddress)) {
throw new Error('token address or user address is missing');
}
- balance = this.getERC20TokenContract(token, options.parent).methods.balanceOf(userAddress).call();
+ balance = this.getERC20TokenContract(token, options.parent)
+ .methods.balanceOf(userAddress)
+ .call();
return [2 /*return*/, balance];
});
});
@@ -97,7 +100,9 @@ var Matic = /** @class */ (function (_super) {
if (options && (!token || !userAddress)) {
throw new Error('token address or user address is missing');
}
- balance = this.getERC721TokenContract(token, options.parent).methods.balanceOf(userAddress).call();
+ balance = this.getERC721TokenContract(token, options.parent)
+ .methods.balanceOf(userAddress)
+ .call();
return [2 /*return*/, balance];
});
});
@@ -109,7 +114,9 @@ var Matic = /** @class */ (function (_super) {
if (options && (!token || !userAddress)) {
throw new Error('token address or user address is missing');
}
- tokenID = this.getERC721TokenContract(token, options.parent).methods.tokenOfOwnerByIndex(userAddress, index).call();
+ tokenID = this.getERC721TokenContract(token, options.parent)
+ .methods.tokenOfOwnerByIndex(userAddress, index)
+ .call();
return [2 /*return*/, tokenID];
});
});
@@ -124,9 +131,7 @@ var Matic = /** @class */ (function (_super) {
throw new Error('options.from, to, token or amount is missing');
}
txObject = this.getERC20TokenContract(token, options.parent).methods.transfer(to, this.encode(amount));
- return [4 /*yield*/, this._fillOptions(options, txObject, options.parent
- ? this.web3Client.getParentWeb3()
- : this.web3Client.getMaticWeb3())];
+ return [4 /*yield*/, this._fillOptions(options, txObject, options.parent ? this.web3Client.getParentWeb3() : this.web3Client.getMaticWeb3())];
case 1:
_options = _a.sent();
if (options.encodeAbi) {
@@ -149,9 +154,7 @@ var Matic = /** @class */ (function (_super) {
throw new Error('options.from, to, token or tokenId is missing');
}
txObject = this.getERC721TokenContract(token, options.parent).methods.transferFrom(options.from, to, tokenId);
- return [4 /*yield*/, this._fillOptions(options, txObject, options.parent
- ? this.web3Client.getParentWeb3()
- : this.web3Client.getMaticWeb3())];
+ return [4 /*yield*/, this._fillOptions(options, txObject, options.parent ? this.web3Client.getParentWeb3() : this.web3Client.getMaticWeb3())];
case 1:
_options = _a.sent();
if (options.encodeAbi) {
@@ -184,16 +187,16 @@ var Matic = /** @class */ (function (_super) {
case 2:
depositReceipt = _b.sent();
if (!depositReceipt) {
- return [2 /*return*/, 'Transaction hash is not Found'];
+ throw new Error('Transaction hash is not Found');
}
newDepositEvent = depositReceipt.logs.find(function (l) { return l.topics[0].toLowerCase() === DepositManager_1.default.NEW_DEPOSIT_EVENT_SIG; });
data = newDepositEvent.data;
- depositId = parseInt(data.substring(data.length - 64), 16);
- return [4 /*yield*/, this.depositManager.depositDataByID(depositId, this.childChainAddress)];
+ depositId = new bn_js_1.default(data.substring(data.length - 64), 16);
+ return [4 /*yield*/, this.depositManager.depositDataByID(depositId, this.childChainAddress[0])];
case 3:
depositExists = _b.sent();
if (!depositExists) {
- return [2 /*return*/, 'Deposit is not processed on Matic chain'];
+ throw new Error('Deposit is not processed on Matic chain');
}
return [2 /*return*/, depositReceipt];
}

MODIFY
dist/root/DepositManager.d.ts
dist/root/DepositManager.d.ts
@@ -7,7 +7,7 @@ export default class DepositManager extends ContractsBase {
static NEW_DEPOSIT_EVENT_SIG: string;
depositManagerContract: Contract;
constructor(depositManager: address, web3Client: Web3Client);
- depositDataByID(depositId: number, childChainAddress: address): Promise<any>;
+ depositDataByID(depositId: BN, childChainAddress: address): Promise<any>;
approveERC20(token: address, amount: BN | string, options?: SendOptions): Promise<any>;
depositERC20(token: address, amount: BN | string, options?: SendOptions): Promise<any>;
depositERC721(token: address, tokenId: string, options?: SendOptions): Promise<any>;

MODIFY
examples/node/deposit-data.js
examples/node/deposit-data.js
@@ -22,11 +22,12 @@ const matic = new Matic({
async function execute() {
await matic.initialize()
matic.setWallet(config.PRIVATE_KEY)
- // return matic.depositDataByHash('0x8cff1ef2b198273fe7f9fb41918cd7e3e8d04c58650614af39b3086e1de1a7e6')
- return matic.depositManager.depositDataByID(101230019, '0xa2EF03edfA084ac9e5Bf110e409Ed5483BAe4101')
+ return matic.depositDataByHash('0x8cff1ef2b198273fe7f9fb41918cd7e3e8d04c58650614af39b3086e1de1a7e6')
+ // return matic.depositManager.depositDataByID(101230019, '0xa2EF03edfA084ac9e5Bf110e409Ed5483BAe4101')
}
-async function executeRaw() { // eslint-disable-line
+async function executeRaw() {
+ // eslint-disable-line
await matic.initialize()
let txParams = await matic.approveERC20TokensForDeposit(token, amount, { from, encodeAbi: true })
let serializedTx = utils.buildRawTransaction(txParams, config.PRIVATE_KEY)

MODIFY
src/index.ts
src/index.ts
@@ -135,8 +135,8 @@ export default class Matic extends ContractsBase {
)
const data = newDepositEvent.data
- const depositId = parseInt(data.substring(data.length - 64), 16)
- const depositExists = await this.depositManager.depositDataByID(depositId, this.childChainAddress)
+ const depositId = new BN(data.substring(data.length - 64), 16)
+ const depositExists = await this.depositManager.depositDataByID(depositId, this.childChainAddress[0])
if (!depositExists) {
throw new Error('Deposit is not processed on Matic chain')
}

MODIFY
src/root/DepositManager.ts
src/root/DepositManager.ts
@@ -16,33 +16,22 @@ export default class DepositManager extends ContractsBase {
super(web3Client)
this.depositManagerContract = new this.web3Client.parentWeb3.eth.Contract(
DepositManagerArtifact.abi,
- depositManager,
+ depositManager
)
}
- async depositDataByID(depositId: number, childChainAddress: address) {
- const childChainContract = new this.web3Client.web3.eth.Contract(
- ChildChainArtifact.abi,
- childChainAddress
- )
+ async depositDataByID(depositId: BN, childChainAddress: address) {
+ const childChainContract = new this.web3Client.web3.eth.Contract(ChildChainArtifact.abi, childChainAddress)
return childChainContract.methods.deposits(this.encode(depositId)).call()
}
- async approveERC20(
- token: address,
- amount: BN | string,
- options?: SendOptions,
- ) {
+ async approveERC20(token: address, amount: BN | string, options?: SendOptions) {
const txObject = this.getERC20TokenContract(token, true).methods.approve(
this.depositManagerContract.options.address,
- this.encode(amount),
+ this.encode(amount)
)
- const _options = await this._fillOptions(
- options,
- txObject,
- this.web3Client.getParentWeb3(),
- )
+ const _options = await this._fillOptions(options, txObject, this.web3Client.getParentWeb3())
if (options.encodeAbi) {
_options.data = txObject.encodeABI()
@@ -53,21 +42,10 @@ export default class DepositManager extends ContractsBase {
return this.web3Client.send(txObject, _options)
}
- async depositERC20(
- token: address,
- amount: BN | string,
- options?: SendOptions,
- ) {
- const txObject = this.depositManagerContract.methods.depositERC20(
- token,
- this.encode(amount),
- )
+ async depositERC20(token: address, amount: BN | string, options?: SendOptions) {
+ const txObject = this.depositManagerContract.methods.depositERC20(token, this.encode(amount))
- const _options = await this._fillOptions(
- options,
- txObject,
- this.web3Client.getParentWeb3(),
- )
+ const _options = await this._fillOptions(options, txObject, this.web3Client.getParentWeb3())
if (options.encodeAbi) {
_options.data = txObject.encodeABI()
@@ -79,44 +57,19 @@ export default class DepositManager extends ContractsBase {
}
depositERC721(token: address, tokenId: string, options?: SendOptions) {
- return this.web3Client.send(
- this.depositManagerContract.methods.depositERC721(token, tokenId),
- options,
- )
+ return this.web3Client.send(this.depositManagerContract.methods.depositERC721(token, tokenId), options)
}
- depositBulk(
- tokens: address[],
- amountOrTokenIds: string[],
- user: address,
- options?: SendOptions,
- ) {
+ depositBulk(tokens: address[], amountOrTokenIds: string[], user: address, options?: SendOptions) {
return this.web3Client.send(
- this.depositManagerContract.methods.depositBulk(
- tokens,
- amountOrTokenIds,
- user,
- ),
- options,
+ this.depositManagerContract.methods.depositBulk(tokens, amountOrTokenIds, user),
+ options
)
}
- async depositERC20ForUser(
- token: address,
- amount: BN | string,
- user: address,
- options?: SendOptions,
- ) {
- const txObject = this.depositManagerContract.methods.depositERC20ForUser(
- token,
- user,
- this.encode(amount),
- )
- const _options = await this._fillOptions(
- options,
- txObject,
- this.web3Client.getParentWeb3(),
- )
+ async depositERC20ForUser(token: address, amount: BN | string, user: address, options?: SendOptions) {
+ const txObject = this.depositManagerContract.methods.depositERC20ForUser(token, user, this.encode(amount))
+ const _options = await this._fillOptions(options, txObject, this.web3Client.getParentWeb3())
if (options.encodeAbi) {
_options.data = txObject.encodeABI()
@@ -127,20 +80,8 @@ export default class DepositManager extends ContractsBase {
return this.web3Client.send(txObject, _options)
}
- depositERC721ForUser(
- token: address,
- tokenId: string,
- user: address,
- options?: SendOptions,
- ) {
- return this.web3Client.send(
- this.depositManagerContract.methods.depositERC721ForUser(
- token,
- user,
- tokenId,
- ),
- options,
- )
+ depositERC721ForUser(token: address, tokenId: string, user: address, options?: SendOptions) {
+ return this.web3Client.send(this.depositManagerContract.methods.depositERC721ForUser(token, user, tokenId), options)
}
async depositEther(amount: BN | string, options: SendOptions = {}) {
@@ -149,7 +90,7 @@ export default class DepositManager extends ContractsBase {
const _options = await this._fillOptions(
Object.assign(options, { value: this.encode(amount) }),
txObject,
- this.web3Client.getParentWeb3(),
+ this.web3Client.getParentWeb3()
)
if (options.encodeAbi) {

use BN instead of int