fix : deposit pos erc20
MODIFY
src/model/base_token.ts
src/model/base_token.ts
@@ -3,7 +3,7 @@ import { ITransactionConfig, ITransactionOption, IContractInitParam } from "../i
import { BaseContractMethod } from "../abstracts";
import { BaseContract } from "./eth_contract";
import { eventBusPromise, merge, IEventBusPromise } from "../utils";
-import { EXTRA_GAS_FOR_PROXY_CALL } from "../constant";
+import { EXTRA_GAS_FOR_PROXY_CALL, LOGGER } from "../constant";
import { ITransactionReceipt } from "../interfaces";
import { ContractWriteResult } from "./contract_write_result";
@@ -26,7 +26,7 @@ export class BaseToken {
}
protected processWrite(method: BaseContractMethod, option: ITransactionOption = {}): Promise<ContractWriteResult> {
-
+ LOGGER.log("process write");
return this.createTransactionConfig(
{
txConfig: option,
@@ -34,6 +34,7 @@ export class BaseToken {
method,
isParent: this.contractParam.isParent
}).then(config => {
+ LOGGER.log("process write config");
if (option.returnTransaction) {
return merge(config, {
data: method.encodeABI(),
@@ -62,8 +63,9 @@ export class BaseToken {
return this.client.config.child.defaultConfig;
}
- protected createTransactionConfig = async ({ txConfig, method, isParent, isWrite }: ITransactionConfigParam) => {
- txConfig = Object.assign(this.parentDefaultConfig, txConfig || {});
+ protected async createTransactionConfig({ txConfig, method, isParent, isWrite }: ITransactionConfigParam) {
+ txConfig = Object.assign(isParent ? this.parentDefaultConfig : this.childDefaultConfig, txConfig || {});
+ console.log("txConfig", txConfig, isParent, isWrite);
const client = isParent ? this.client.parent.client :
this.client.child.client;
if (isWrite) {
@@ -75,13 +77,13 @@ export class BaseToken {
!txConfig.nonce ? client.getTransactionCount(txConfig.from as string, 'pending') : txConfig.nonce,
!txConfig.chainId ? client.getChainId() : txConfig.chainId,
]);
-
+ console.log("calculated");
txConfig.gas = isParent ? Number(gas) + EXTRA_GAS_FOR_PROXY_CALL : gas;
txConfig.gasPrice = gasPrice;
txConfig.nonce = nonce;
txConfig.chainId = chainId;
}
return txConfig;
- };
+ }
}
\ No newline at end of file

MODIFY
src/pos/erc20.ts
src/pos/erc20.ts
@@ -69,10 +69,16 @@ export class ERC20 extends POSToken {
* @memberof ERC20
*/
deposit(amount: TYPE_AMOUNT, userAddress: string, option?: ITransactionOption) {
+ console.log("this.rootChainManager", this.rootChainManager['contract'].address);
+ const amountInABI = this.client.parent.client.encodeParameters(
+ [formatAmount(amount)],
+ ['uint256'],
+ );
+ console.log("amountInByte", amountInABI);
return this.rootChainManager.deposit(
userAddress,
this.contractParam.tokenAddress,
- amount,
+ amountInABI,
option
);
}

MODIFY
src/pos/root_chain_manager.ts
src/pos/root_chain_manager.ts
@@ -63,12 +63,12 @@ export class RootChainManager extends BaseToken {
return ans.mul(CHECKPOINT_INTERVAL);
}
- deposit(userAddress: string, tokenAddress: string, amount: TYPE_AMOUNT, option?: ITransactionOption) {
+ deposit(userAddress: string, tokenAddress: string, depositData: string, option?: ITransactionOption) {
const method = this.method(
"depositFor",
userAddress,
tokenAddress,
- formatAmount(amount)
+ depositData
);
return this.processWrite(method, option);

MODIFY
test/debug.js
test/debug.js
@@ -57,7 +57,7 @@ const execute = async () => {
// const balance = await parentErc20.getBalance(from);
// console.log('balance', balance);
- const approveResult = await parentErc20.approve('1000000000000000');
+ const approveResult = await parentErc20.deposit('1000000000000000', from);
console.log('txHash', await approveResult.getTransactionHash());
console.log('receipt', await approveResult.getReceipt());
@@ -81,4 +81,7 @@ const execute = async () => {
execute().then(_ => {
process.exit(0)
+}).catch(err => {
+ console.error(err);
+ process.exit(0);
})

fix : deposit pos erc20