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

refactor(abstract-eth): move methods to abstract-eth #4039

Merged
merged 1 commit into from
Nov 11, 2023

Conversation

gianchandania
Copy link
Contributor

@gianchandania gianchandania commented Nov 7, 2023

This PR moves the common EthLike methods to AbstractEthLikeNewCoins class. EthLikeToken also inherits from this new class. ETH and Polygon classes have been modified to inherit from this new class. All the tokens like BscToken, PolygonToken are inheriting EthLikeToken class, but Erc20Token is still inheriting Eth class because ERC20 tokens use some of the methods defined in the Eth class like signing methods

WIN-1012
TICKET: WIN-1012

signingKeyNonce?: number;
walletContractAddress?: string;
prv: string;
recipients?: Recipient[];
Copy link
Contributor Author

@gianchandania gianchandania Nov 8, 2023

Choose a reason for hiding this comment

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

Here I had to make all the fields optional because I was getting an error that the params passed to signTransaction are not compatible as we also have signTransaction in AbstractEthLikeCoin class and the interface used there is not having all these fields.

Copy link
Contributor

Choose a reason for hiding this comment

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

Moving from required to optional isnt a breaking change right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Correct, will remove this from breaking change

gasLimit?: number;
gasPrice?: number;
custodianTransactionId?: string;
}
Copy link
Contributor Author

@gianchandania gianchandania Nov 8, 2023

Choose a reason for hiding this comment

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

Had to make all fields optional because of the same issue mentioned above with signTransaction method

txInfo: TxInfo;
feeInfo: EthTransactionFee;
source: string;
dataToSign: string;
nextContractSequenceId?: string;
nextContractSequenceId?: number;
Copy link
Contributor Author

@gianchandania gianchandania Nov 8, 2023

Choose a reason for hiding this comment

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

BREAKING CHANGE: Type of nextContractSequenceId is changed to number to avoid typescript error of incompatible function params for signTransaction method in AbstractEthLikeNewCoins and AbstractEthLikeCoin

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Have created a ticket WIN-1098 to address the change required in OVC because of this

export interface TransactionPrebuild extends BaseTransactionPrebuild {
hopTransaction?: HopPrebuild;
buildParams: {
recipients: Recipient[];
};
recipients: TransactionRecipient[];
nextContractSequenceId: string;
nextContractSequenceId: number;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

BREAKING CHANGE: Type of nextContractSequenceId is changed to number to avoid typescript error of incompatible function params for signTransaction method in AbstractEthLikeNewCoins and AbstractEthLikeCoin

@gianchandania gianchandania force-pushed the WIN-1012-move-methods-from-sdk-coin-eth branch 3 times, most recently from 09bb52f to 00ac185 Compare November 8, 2023 14:43
* @param params.prv
* @returns {{txHex: string}}
*/
async signFinalPolygon(params: SignFinalOptions): Promise<FullySignedTransaction> {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

BREAKING CHANGE: signFinalPolygon method name is updated to signFinalEthLike so that it can be used for other EthLike coins

return 'PolygonMumbai';
}
return 'PolygonMainnet';
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

BREAKING CHANGE: getCustomChainName method is removed and getCustomChainCommon method is added in the AbstractEthLikeNewCoins class to return ethlike common object

const defaultHardfork = !!params.eip1559 ? 'london' : optionalDeps.EthCommon.Hardfork.TangerineWhistle;
let customChainCommon;
// if replay protection options are set, override the default common setting
if (params.replayProtectionOptions) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

BREAKING CHANGE: replayProtectionOptions is not optional in buildTransaction method for EthLike coins and needs to be passed to derive the Eth common object from the chainId

@gianchandania gianchandania force-pushed the WIN-1012-move-methods-from-sdk-coin-eth branch 2 times, most recently from edb0910 to 9a2ec21 Compare November 8, 2023 15:58
@gianchandania gianchandania marked this pull request as ready for review November 8, 2023 16:42
@gianchandania gianchandania requested review from a team as code owners November 8, 2023 16:42
Copy link
Contributor

@zahin-mohammad zahin-mohammad left a comment

Choose a reason for hiding this comment

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

Will reserve a final review until @BitGo/ethalt-team reviews.

Also for breaking change commits please ensure that its the last grouping with no spaced lines.

Example:

refactor(abstract-eth): move methods to abstract-eth

<description>

BREAKING CHANGE: something changed
TICKET: WIN-1012

@@ -0,0 +1,16 @@
// Mapping of all supported coins with their chainIds
export const EthLikeCoinNameFromChainId = {
Copy link
Contributor

Choose a reason for hiding this comment

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

can we create this map using statics?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added

sachushaji
sachushaji previously approved these changes Nov 9, 2023
Copy link
Contributor

@sachushaji sachushaji left a comment

Choose a reason for hiding this comment

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

Nice Work!!!. Some small NITs

throw new Error('Invalid address: ' + recipient.address);
}

let amount;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
let amount;
let amount: BigNumber;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

addressed

* @param address
* @returns {*}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* @returns {*}
* @returns {Promise<number>}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

addressed

Comment on lines 821 to 845
* @param txInfo
* @param ethTx
* @param userKey
* @param backupKey
* @param gasPrice
* @param gasLimit
* @param eip1559
* @param replayProtectionOptions
* @returns {Promise<OfflineVaultTxInfo>}
Copy link
Contributor

Choose a reason for hiding this comment

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

Lets add JSDOC consistently with all other functions in the file

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added

modules/sdk-coin-eth/src/eth.ts Show resolved Hide resolved
modules/sdk-coin-eth/src/eth.ts Outdated Show resolved Hide resolved
@gianchandania gianchandania force-pushed the WIN-1012-move-methods-from-sdk-coin-eth branch 3 times, most recently from 285d428 to 3b72cb5 Compare November 9, 2023 11:36
@gianchandania
Copy link
Contributor Author

Will reserve a final review until @BitGo/ethalt-team reviews.

Also for breaking change commits please ensure that its the last grouping with no spaced lines.

Example:

refactor(abstract-eth): move methods to abstract-eth

<description>

BREAKING CHANGE: something changed
TICKET: WIN-1012

removed blank spaces from BREAKING CHANGE description

sachushaji
sachushaji previously approved these changes Nov 10, 2023
Copy link
Contributor

@sachushaji sachushaji left a comment

Choose a reason for hiding this comment

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

Awesome!! 👍

@gianchandania gianchandania force-pushed the WIN-1012-move-methods-from-sdk-coin-eth branch from 42c2a6c to 1921f62 Compare November 10, 2023 10:20
@gianchandania
Copy link
Contributor Author

Squashed the commits

dpkjnr
dpkjnr previously approved these changes Nov 10, 2023
@gianchandania gianchandania dismissed stale reviews from dpkjnr and sachushaji via a25ee6a November 10, 2023 17:52
WIN-1012

BREAKING CHANGE: Type of nextContractSequenceId field in TransactionPrebuild
interface is changed from string to number in AbstractEthLikeCoin and AbstractEthLikeNewCoins classes.
getCustomChainName method is removed from Polygon class because a common
method getCustomChainCommon has been added to AbstractEthLikeNewCoins
class for all EthLike coins. replayProtectionOptions is not optional in buildTransaction method in AbstractEthLikeNewCoins
and needs to be passed to derive the Eth common object from the chainId.
signFinalPolygon method name from Polygon class is updated to signFinalEthLike so that
it can be used for other EthLike coins. getBaseFactor method in Eth
and Polygon class returns number instead of string just to align with
AbstractEthLikeCoin
Ticket: WIN-1012
@gianchandania gianchandania force-pushed the WIN-1012-move-methods-from-sdk-coin-eth branch from a25ee6a to af8bd10 Compare November 10, 2023 17:59
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.

5 participants