Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions modules/abstract-eth/src/abstractEthLikeNewCoins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ export type RecoverOptions = {
intendedChain?: string;
common?: EthLikeCommon.default;
derivationSeed?: string;
apiKey?: string;
} & TSSRecoverOptions;

export type GetBatchExecutionInfoRT = {
Expand Down Expand Up @@ -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> {
Copy link
Contributor

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

We don't need to update this method signature.
Please refer the implementation of recoveryBlockchainExplorerQuery in Coredoa, Oas, Flr (any other EVM coin) to see how we are fetching APIKey there.

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}`);
Expand Down Expand Up @@ -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> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above,
Please refer the implementation of recoveryBlockchainExplorerQuery in Coredoa, Oas, Flr (any other EVM coin) to see how we are fetching APIKey there.

Copy link
Contributor

Choose a reason for hiding this comment

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

+1

// Get nonce for backup key (should be 0)
let nonce = 0;

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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}`);
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)) {
Expand All @@ -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> {
Copy link
Contributor

Choose a reason for hiding this comment

The 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');
}

Expand Down Expand Up @@ -2844,3 +2845,4 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin {
}
}
}

Loading
Loading