-
Notifications
You must be signed in to change notification settings - Fork 299
feat(bsc): added support for mpcv2 in recovery #5957
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -253,6 +253,7 @@ export type RecoverOptions = { | |
| intendedChain?: string; | ||
| common?: EthLikeCommon.default; | ||
| derivationSeed?: string; | ||
| apiKey?: string; | ||
| } & TSSRecoverOptions; | ||
|
|
||
| export type GetBatchExecutionInfoRT = { | ||
|
|
@@ -531,13 +532,13 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin { | |
| * @param {String} address - the ETHLike address | ||
| * @returns {BigNumber} address balance | ||
| */ | ||
| async queryAddressBalance(address: string): Promise<any> { | ||
| async queryAddressBalance(address: string, apiKey?: string): Promise<any> { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't need to update this method signature. |
||
| const result = await this.recoveryBlockchainExplorerQuery({ | ||
| chainid: this.getChainId().toString(), | ||
| module: 'account', | ||
| action: 'balance', | ||
| address: address, | ||
| }); | ||
| }, apiKey); | ||
| // 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 the explorer, got: ${result.result}`); | ||
|
|
@@ -839,7 +840,7 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin { | |
| * @param {string} address | ||
| * @returns {Promise<number>} | ||
| */ | ||
| async getAddressNonce(address: string): Promise<number> { | ||
| async getAddressNonce(address: string, apiKey?: string): Promise<number> { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above,
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 |
||
| // Get nonce for backup key (should be 0) | ||
| let nonce = 0; | ||
|
|
||
|
|
@@ -1943,7 +1944,7 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin { | |
| } | ||
| } | ||
|
|
||
| private async getGasValues(params: RecoverOptions): Promise<{ gasLimit: number; gasPrice: Buffer }> { | ||
| protected async getGasValues(params: RecoverOptions): Promise<{ gasLimit: number; gasPrice: Buffer }> { | ||
| const gasLimit = new optionalDeps.ethUtil.BN(this.setGasLimit(params.gasLimit)); | ||
| const gasPrice = params.eip1559 | ||
| ? new optionalDeps.ethUtil.BN(params.eip1559.maxFeePerGas) | ||
|
|
@@ -2028,7 +2029,7 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin { | |
| } as unknown as ECDSAMethodTypes.Signature; | ||
| const signatureHex = Buffer.from(signature.toString(), 'hex'); | ||
| const txBuilder = this.getTransactionBuilder(getCommon(this.getNetwork() as EthLikeNetwork)); | ||
| txBuilder.from(transaction.serializedTxHex as string); | ||
| txBuilder.from(addHexPrefix(transaction.serializedTxHex) as string); | ||
|
|
||
| if (!transaction.coinSpecific?.commonKeyChain) { | ||
| throw new Error(`Missing common keychain for transaction at index ${i}`); | ||
|
|
@@ -2163,9 +2164,9 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin { | |
| }; | ||
| } | ||
|
|
||
| private async buildTssRecoveryTxn(baseAddress: string, gasPrice: any, gasLimit: any, params: RecoverOptions) { | ||
| const nonce = await this.getAddressNonce(baseAddress); | ||
| const txAmount = await this.validateBalanceAndGetTxAmount(baseAddress, gasPrice, gasLimit); | ||
| protected async buildTssRecoveryTxn(baseAddress: string, gasPrice: any, gasLimit: any, params: RecoverOptions) { | ||
| const nonce = await this.getAddressNonce(baseAddress, params.apiKey); | ||
| const txAmount = await this.validateBalanceAndGetTxAmount(baseAddress, gasPrice, gasLimit, params.apiKey); | ||
| const recipients = [ | ||
| { | ||
| address: params.recoveryDestination, | ||
|
|
@@ -2194,8 +2195,8 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin { | |
| return { txInfo, tx, nonce }; | ||
| } | ||
|
|
||
| async validateBalanceAndGetTxAmount(baseAddress: string, gasPrice: BN, gasLimit: BN) { | ||
| const baseAddressBalance = await this.queryAddressBalance(baseAddress); | ||
| async validateBalanceAndGetTxAmount(baseAddress: string, gasPrice: BN, gasLimit: BN, apiKey?: string) { | ||
| const baseAddressBalance = await this.queryAddressBalance(baseAddress, apiKey); | ||
| const totalGasNeeded = gasPrice.mul(gasLimit); | ||
| const weiToGwei = new BN(10 ** 9); | ||
| if (baseAddressBalance.lt(totalGasNeeded)) { | ||
|
|
@@ -2209,7 +2210,7 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin { | |
| return txAmount; | ||
| } | ||
|
|
||
| async recoveryBlockchainExplorerQuery(query: Record<string, string>): Promise<any> { | ||
| async recoveryBlockchainExplorerQuery(query: Record<string, string>, apiKey?: string): Promise<any> { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changing this function signature in abstract class will break recovery flow for all other coins. |
||
| throw new Error('method not implemented'); | ||
| } | ||
|
|
||
|
|
@@ -2844,3 +2845,4 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin { | |
| } | ||
| } | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's update the function documentation with this new param.