Skip to content

Commit 9ca7ae7

Browse files
chore: migrating suported eth like coins to use etherscan api v2
Ticket: WIN-5684 TICKET: WIN-5684
1 parent bd4569b commit 9ca7ae7

File tree

24 files changed

+91
-32
lines changed

24 files changed

+91
-32
lines changed

modules/abstract-eth/src/abstractEthLikeCoin.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @prettier
33
*/
44
import type * as EthLikeCommon from '@ethereumjs/common';
5-
import { CoinFamily, BaseCoin as StaticsBaseCoin } from '@bitgo/statics';
5+
import { CoinFamily, BaseCoin as StaticsBaseCoin, EthereumNetwork } from '@bitgo/statics';
66
import { bip32 } from '@bitgo/secp256k1';
77
import { randomBytes } from 'crypto';
88
import {
@@ -112,6 +112,10 @@ export abstract class AbstractEthLikeCoin extends BaseCoin {
112112
return Math.pow(10, this._staticsCoin.decimalPlaces);
113113
}
114114

115+
getChainId(): number {
116+
return (this._staticsCoin.network as EthereumNetwork).chainId;
117+
}
118+
115119
/** @inheritDoc */
116120
isEVM(): boolean {
117121
return true;

modules/abstract-eth/src/abstractEthLikeNewCoins.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,7 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin {
533533
*/
534534
async queryAddressBalance(address: string): Promise<any> {
535535
const result = await this.recoveryBlockchainExplorerQuery({
536+
chainid: this.getChainId().toString(),
536537
module: 'account',
537538
action: 'balance',
538539
address: address,
@@ -634,6 +635,7 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin {
634635
const sequenceIdArgs = optionalDeps.ethAbi.rawEncode([], []);
635636
const sequenceIdData = Buffer.concat([sequenceIdMethodSignature, sequenceIdArgs]).toString('hex');
636637
const result = await this.recoveryBlockchainExplorerQuery({
638+
chainid: this.getChainId().toString(),
637639
module: 'proxy',
638640
action: 'eth_call',
639641
to: address,
@@ -842,6 +844,7 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin {
842844
let nonce = 0;
843845

844846
const result = await this.recoveryBlockchainExplorerQuery({
847+
chainid: this.getChainId().toString(),
845848
module: 'account',
846849
action: 'txlist',
847850
address,
@@ -1631,6 +1634,7 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin {
16311634
}
16321635

16331636
const result = await this.recoveryBlockchainExplorerQuery({
1637+
chainid: this.getChainId().toString(),
16341638
module: 'account',
16351639
action: 'tokenbalance',
16361640
contractaddress: tokenContractAddress,
@@ -2775,6 +2779,7 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin {
27752779
async getGasPriceFromExternalAPI(wrongChainCoin: string): Promise<BN> {
27762780
try {
27772781
const res = await this.recoveryBlockchainExplorerQuery({
2782+
chainid: this.getChainId().toString(),
27782783
module: 'proxy',
27792784
action: 'eth_gasPrice',
27802785
});
@@ -2796,6 +2801,7 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin {
27962801
async getGasLimitFromExternalAPI(intendedChain: string, from: string, to: string, data: string): Promise<BN> {
27972802
try {
27982803
const res = await this.recoveryBlockchainExplorerQuery({
2804+
chainid: this.getChainId().toString(),
27992805
module: 'proxy',
28002806
action: 'eth_estimateGas',
28012807
from,

modules/abstract-eth/src/ethLikeToken.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ export class EthLikeToken extends AbstractEthLikeNewCoins {
258258
let backupKeyNonce = 0;
259259

260260
const result = await this.recoveryBlockchainExplorerQuery({
261+
chainid: this.getChainId().toString(),
261262
module: 'account',
262263
action: 'txlist',
263264
address: backupKeyAddress,

modules/bitgo/test/v2/lib/recovery-nocks.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -407,9 +407,12 @@ module.exports.nockEthLikeRecovery = function (bitgo, nockData = nockEthData) {
407407
if (apiKey) {
408408
data.params.apiKey = apiKey;
409409
}
410-
nock('https://api-holesky.etherscan.io/').get('/api').query(data.params).reply(200, data.response);
411-
nock('https://api-amoy.polygonscan.com').get('/api').query(data.params).reply(200, data.response);
412-
nock('https://api-testnet.bscscan.com').get('/api').query(data.params).reply(200, data.response);
410+
data.params[`chainid`] = '17000';
411+
nock('https://api.etherscan.io/v2').get('/api').query(data.params).reply(200, data.response);
412+
data.params[`chainid`] = '80002';
413+
nock('https://api.etherscan.io/v2').get('/api').query(data.params).reply(200, data.response);
414+
data.params[`chainid`] = '97';
415+
nock('https://api.etherscan.io/v2').get('/api').query(data.params).reply(200, data.response);
413416
});
414417
};
415418

@@ -421,12 +424,13 @@ module.exports.nockEtherscanRateLimitError = function () {
421424
};
422425

423426
const params = {
427+
chainid: '17000',
424428
module: 'account',
425429
action: 'txlist',
426430
address: '0x74c2137d54b0fc9f907e13f14e0dd18485fee924',
427431
};
428432

429-
nock('https://api-holesky.etherscan.io').get('/api').query(params).reply(200, response);
433+
nock('https://api.etherscan.io/v2').get('/api').query(params).reply(200, response);
430434
};
431435

432436
module.exports.nockXlmRecovery = function () {

modules/sdk-coin-arbeth/test/fixtures/arbeth.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export function getTxListRequest(address: string) {
22
return {
3+
chainid: '421614',
34
module: 'account',
45
action: 'txlist',
56
address: address,
@@ -14,6 +15,7 @@ export const getTxListResponse = {
1415

1516
export function getBalanceRequest(address: string) {
1617
return {
18+
chainid: '421614',
1719
module: 'account',
1820
action: 'balance',
1921
address: address,
@@ -22,6 +24,7 @@ export function getBalanceRequest(address: string) {
2224

2325
export function getTokenBalanceRequest(tokenContractAddress: string, address: string) {
2426
return {
27+
chainid: '421614',
2528
module: 'account',
2629
action: 'tokenbalance',
2730
contractaddress: tokenContractAddress,
@@ -55,6 +58,7 @@ export const getFeeAddressLowBalanceResponse = {
5558
};
5659

5760
export const getContractCallRequest = {
61+
chainid: '421614',
5862
module: 'proxy',
5963
action: 'eth_call',
6064
to: '0xdf07117705a9f8dc4c2a78de66b7f1797dba9d4e',

modules/sdk-coin-arbeth/test/unit/arbeth.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ describe('Arbitrum', function () {
535535
});
536536

537537
describe('Recover transaction:', function () {
538-
const baseUrl = 'https://api-sepolia.arbiscan.io';
538+
const baseUrl = common.Environments.test.arbiscanBaseUrl as string;
539539
const userXpub =
540540
'xpub661MyMwAqRbcEeTc8789MK5PUGEYiPG4F4V17n2Rd2LoTATA1XoCnJT5FAYAShQxSxtFjpo5NHmcWwTp2LiWGBMwpUcAA3HywhxivgYfq7q';
541541
const userXprv =

modules/sdk-coin-arbeth/test/unit/arbethToken.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ import { BitGoAPI } from '@bitgo/sdk-api';
66

77
import { ArbethToken } from '../../src';
88
import * as mockData from '../fixtures/arbeth';
9+
import { common } from '@bitgo/sdk-core';
910

1011
describe('Arbeth Token:', function () {
1112
let bitgo: TestBitGoAPI;
1213
let arbethTokenCoin;
13-
const baseUrl = 'https://api-sepolia.arbiscan.io';
14+
const baseUrl = common.Environments.test.arbiscanBaseUrl as string;
1415
const tokenName = 'tarbeth:link';
1516
const walletContractAddress = '0xdf07117705a9f8dc4c2a78de66b7f1797dba9d4e';
1617
const tokenContractAddress = '0xe5b6c29411b3ad31c3613bba0145293fc9957256';

modules/sdk-coin-eth/src/erc20Token.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ export class Erc20Token extends Eth {
208208
let backupKeyNonce = 0;
209209

210210
const result = await this.recoveryBlockchainExplorerQuery({
211+
chainid: this.getChainId().toString(),
211212
module: 'account',
212213
action: 'txlist',
213214
address: backupKeyAddress,

modules/sdk-coin-eth/test/fixtures/eth.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ module.exports.WRWUnsignedSweepERC20Tx = {
181181

182182
export function getTxListRequest(address: string) {
183183
return {
184+
chainid: '17000',
184185
module: 'account',
185186
action: 'txlist',
186187
address: address,
@@ -195,6 +196,7 @@ export const getTxListResponse = {
195196

196197
export function getBalanceRequest(address: string) {
197198
return {
199+
chainid: '17000',
198200
module: 'account',
199201
action: 'balance',
200202
address: address,
@@ -208,6 +210,7 @@ export const getBalanceResponse = {
208210
};
209211

210212
export const getContractCallRequest = {
213+
chainid: '17000',
211214
module: 'proxy',
212215
action: 'eth_call',
213216
to: '0xdf07117705a9f8dc4c2a78de66b7f1797dba9d4e',

modules/sdk-coin-eth/test/unit/eth.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,7 @@ describe('ETH:', function () {
839839
});
840840

841841
describe('EVM Cross Chain Recovery', function () {
842-
const baseUrl = 'https://api-holesky.etherscan.io';
842+
const baseUrl = common.Environments.test.etherscanBaseUrl as string;
843843
it('should build a recovery transaction for hot wallet', async function () {
844844
const userKey =
845845
'{"iv":"VFZ3jvXhxo1Z+Yaf2MtZnA==","v":1,"iter":10000,"ks":256,"ts":64,"mode"\n' +
@@ -884,7 +884,7 @@ describe('ETH:', function () {
884884
});
885885

886886
describe('Non-BitGo Recovery for Hot Wallets (MPCv2)', function () {
887-
const baseUrl = 'https://api-holesky.etherscan.io';
887+
const baseUrl = common.Environments.test.etherscanBaseUrl as string;
888888
let bitgo: TestBitGoAPI;
889889
let basecoin: Hteth;
890890

@@ -955,7 +955,7 @@ describe('ETH:', function () {
955955
});
956956

957957
describe('Build Unsigned Sweep for Self-Custody Cold Wallets (MPCv2)', function () {
958-
const baseUrl = 'https://api-holesky.etherscan.io';
958+
const baseUrl = common.Environments.test.etherscanBaseUrl as string;
959959
let bitgo: TestBitGoAPI;
960960
let basecoin: Hteth;
961961

0 commit comments

Comments
 (0)