Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(avaxc) : wrw support for evm ccr #4944

Closed
wants to merge 1 commit into from

Conversation

nrjsuthar
Copy link

chore(avaxc) : wrw support for evm ccr

TICKET: COIN-1708

@nrjsuthar nrjsuthar force-pushed the feature/COIN-1708-new branch 2 times, most recently from 773895f to c116a8e Compare September 25, 2024 12:41
@kamleshmugdiya
Copy link
Contributor

tests are failing

Copy link
Contributor

@kamleshmugdiya kamleshmugdiya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this defeats the purpose of inheritance and code reusability.

return userGasPrice;
}

async recoveryBlockchainExplorerQuery(query: Record<string, any>): Promise<any> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add JSdocs

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

Comment on lines 37 to 47
setGasLimit(userGasLimit?: number): number {
if (!userGasLimit) {
return ethGasConfigs.defaultGasLimit;
}
const gasLimitMax = ethGasConfigs.maximumGasLimit;
const gasLimitMin = ethGasConfigs.minimumGasLimit;
if (userGasLimit < gasLimitMin || userGasLimit > gasLimitMax) {
throw new Error(`Gas limit must be between ${gasLimitMin} and ${gasLimitMax}`);
}
return userGasLimit;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this required?
the implementation of setGasLimit in AbstractEthLikeNewCoins is the same.

Comment on lines 49 to 60
setGasPrice(userGasPrice?: number): number {
if (!userGasPrice) {
return ethGasConfigs.defaultGasPrice;
}

const gasPriceMax = ethGasConfigs.maximumGasPrice;
const gasPriceMin = ethGasConfigs.minimumGasPrice;
if (userGasPrice < gasPriceMin || userGasPrice > gasPriceMax) {
throw new Error(`Gas price must be between ${gasPriceMin} and ${gasPriceMax}`);
}
return userGasPrice;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this required?
the implementation of setGasPrice in AbstractEthLikeNewCoins is the same.

Comment on lines 62 to 73
async recoveryBlockchainExplorerQuery(query: Record<string, any>): Promise<any> {
const env = this.bitgo.getEnv();
const response = await request.post(common.Environments[env].avaxcNetworkBaseUrl + '/ext/bc/C/rpc').send(query);
if (!response.ok) {
throw new Error('could not reach avax.network');
}

if (response.body.status === '0' && response.body.message === 'NOTOK') {
throw new Error('avax.network rate limit reached');
}
return response.body;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this required?
the implementation of recoveryBlockchainExplorerQuery in AbstractEthLikeNewCoins is the same.

Comment on lines 75 to 88
async getAddressNonce(address: string): Promise<number> {
// Get nonce for backup key (should be 0)
const result = await this.recoveryBlockchainExplorerQuery({
jsonrpc: '2.0',
method: 'eth_getTransactionCount',
params: [address, 'latest'],
id: 1,
});
if (!result || isNaN(result.result)) {
throw new Error('Unable to find next nonce from avax.network, got: ' + JSON.stringify(result));
}
const nonceHex = result.result;
return new optionalDeps.ethUtil.BN(nonceHex.slice(2), 16).toNumber();
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

Comment on lines 90 to 103
async queryAddressBalance(address: string): Promise<BN> {
const result = await this.recoveryBlockchainExplorerQuery({
jsonrpc: '2.0',
method: 'eth_getBalance',
params: [address, 'latest'],
id: 1,
});
// throw if the result does not exist or the result is not a valid number
if (!result || !result.result || isNaN(result.result)) {
throw new Error(`Could not obtain address balance for ${address} from avax.network, got: ${result.result}`);
}
const nativeBalanceHex = result.result;
return new optionalDeps.ethUtil.BN(nativeBalanceHex.slice(2), 16);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

Comment on lines 105 to 122
async querySequenceId(address: string): Promise<number> {
// Get sequence ID using contract call
const sequenceIdMethodSignature = optionalDeps.ethAbi.methodID('getNextSequenceId', []);
const sequenceIdArgs = optionalDeps.ethAbi.rawEncode([], []);
const sequenceIdData = Buffer.concat([sequenceIdMethodSignature, sequenceIdArgs]).toString('hex');
const sequenceIdDataHex = optionalDeps.ethUtil.addHexPrefix(sequenceIdData);
const result = await this.recoveryBlockchainExplorerQuery({
jsonrpc: '2.0',
method: 'eth_call',
params: [{ to: address, data: sequenceIdDataHex }, 'latest'],
id: 1,
});
if (!result || !result.result) {
throw new Error('Could not obtain sequence ID from avax.network, got: ' + result.result);
}
const sequenceIdHex = result.result;
return new optionalDeps.ethUtil.BN(sequenceIdHex.slice(2), 16).toNumber();
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

Comment on lines 329 to 338
async getGasPriceFromExternalAPI(): Promise<BN> {
try {
// COIN -1708 : hardcoded for half signing
const gasPrice = new BN(250000);
console.log(` Got hardcoded gas price: ${gasPrice}`);
return gasPrice;
} catch (e) {
throw new Error('Failed to get gas price');
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

@nrjsuthar
Copy link
Author

@kamleshmugdiya
This PR #4925 had the change you mentioned, where the relationship exists. The changes in the current PR were because of the Gas and Limit, wherein all the parent methods are copied. The ideal change would be to extend avaxc class with abstractEthLikeNewCoin (mentioned PR), but removed as no one was sure of the change.

@nrjsuthar
Copy link
Author

Also, the gas price and limit from the explorer were not required here for the half sign.

@nrjsuthar
Copy link
Author

tests are failing

on it

@nrjsuthar nrjsuthar force-pushed the feature/COIN-1708-new branch 2 times, most recently from 69b11e7 to bf631db Compare September 25, 2024 17:04
@kamleshmugdiya
Copy link
Contributor

@kamleshmugdiya This PR #4925 had the change you mentioned, where the relationship exists. The changes in the current PR were because of the Gas and Limit, wherein all the parent methods are copied. The ideal change would be to extend avaxc class with abstractEthLikeNewCoin (mentioned PR), but removed as no one was sure of the change.

I don't understand this, if the function has the same impl in AbstractEthLikeNewCoins, what is the need to override with the same code in the new class?

@nrjsuthar
Copy link
Author

@kamleshmugdiya This PR #4925 had the change you mentioned, where the relationship exists. The changes in the current PR were because of the Gas and Limit, wherein all the parent methods are copied. The ideal change would be to extend avaxc class with abstractEthLikeNewCoin (mentioned PR), but removed as no one was sure of the change.

I don't understand this, if the function has the same impl in AbstractEthLikeNewCoins, what is the need to override with the same code in the new class?

This was based on testing, for each of the issues, the method has been copied.

Example:

A -> B -> C is the method flow and A has to be changed, now i we need to change the method A over here, we will need to override all its parents, the sub method will not be able to be called.

@kamleshmugdiya
Copy link
Contributor

@kamleshmugdiya This PR #4925 had the change you mentioned, where the relationship exists. The changes in the current PR were because of the Gas and Limit, wherein all the parent methods are copied. The ideal change would be to extend avaxc class with abstractEthLikeNewCoin (mentioned PR), but removed as no one was sure of the change.

I don't understand this, if the function has the same impl in AbstractEthLikeNewCoins, what is the need to override with the same code in the new class?

This was based on testing, for each of the issues, the method has been copied.

Example:

A -> B -> C is the method flow and A has to be changed, now i we need to change the method A over here, we will need to override all its parents, the sub method will not be able to be called.

what testing?
and the methods that I pointed out, do they have any difference in implementation vs the AbstractEthLikeNewCoins?
they all looked the same to me.

@kamleshmugdiya
Copy link
Contributor

pipeline failing again

@nrjsuthar nrjsuthar closed this Sep 26, 2024
@nrjsuthar nrjsuthar deleted the feature/COIN-1708-new branch September 26, 2024 17:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants