Skip to content

Commit f4a8ef4

Browse files
Merge pull request #6334 from BitGo/WIN-5969
feat: use common evm sdk in account-lib & coin factory
2 parents 4f4593b + 743fdb2 commit f4a8ef4

File tree

9 files changed

+123
-382
lines changed

9 files changed

+123
-382
lines changed

modules/account-lib/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
"@bitgo/sdk-coin-dot": "^4.3.2",
4848
"@bitgo/sdk-coin-etc": "^2.3.2",
4949
"@bitgo/sdk-coin-eth": "^24.6.2",
50+
"@bitgo/sdk-coin-evm": "^1.1.0",
5051
"@bitgo/sdk-coin-flr": "^1.3.2",
5152
"@bitgo/sdk-coin-hash": "^3.1.2",
5253
"@bitgo/sdk-coin-hbar": "^2.2.2",

modules/account-lib/src/index.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
accountLibBaseCoin,
99
acountLibCrypto,
1010
} from '@bitgo/sdk-core';
11-
import { BaseCoin as CoinConfig, coins } from '@bitgo/statics';
11+
import { BaseCoin as CoinConfig, CoinFeature, coins } from '@bitgo/statics';
1212
export { Ed25519BIP32, Eddsa };
1313

1414
/**
@@ -173,6 +173,9 @@ export { Icp };
173173
import * as Flr from '@bitgo/sdk-coin-flr';
174174
export { Flr };
175175

176+
import * as EvmCoin from '@bitgo/sdk-coin-evm';
177+
export { EvmCoin };
178+
176179
import * as Sgb from '@bitgo/sdk-coin-sgb';
177180
export { Sgb };
178181

@@ -308,6 +311,12 @@ const coinBuilderMap = {
308311
tvet: Vet.TransactionBuilderFactory,
309312
};
310313

314+
coins
315+
.filter((coin) => coin.features.includes(CoinFeature.SHARED_EVM_SDK))
316+
.forEach((coin) => {
317+
coinBuilderMap[coin.name] = EvmCoin.TransactionBuilder;
318+
});
319+
311320
/**
312321
* Get the list of coin tickers supported by this library.
313322
*/

modules/account-lib/test/unit/keyPair/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ describe('Key Pair Factory', () => {
1212
describe('coinToKey map initialization', function () {
1313
const supportedCoinsExceptTestnet = Object.keys(coinModules)
1414
// TODO(BG-40990): temporarily disable eth2 from the test for bls not initialized error
15-
.filter((k) => coinModules[k].KeyPair && k.trim().toLowerCase() !== 'eth2');
15+
.filter((k) => coinModules[k].KeyPair && !['eth2', 'evmcoin'].includes(k.trim().toLowerCase()));
1616

1717
supportedCoinsExceptTestnet.forEach((coinName) => {
1818
it(`should initialize a ${coinName} keyPair map`, () => {

modules/account-lib/tsconfig.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@
5252
{
5353
"path": "../sdk-coin-eth"
5454
},
55+
{
56+
"path": "../sdk-coin-evm"
57+
},
5558
{
5659
"path": "../sdk-coin-flr"
5760
},

modules/bitgo/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
"@bitgo/sdk-coin-eth": "^24.6.2",
8181
"@bitgo/sdk-coin-ethlike": "^1.3.2",
8282
"@bitgo/sdk-coin-ethw": "^20.1.2",
83+
"@bitgo/sdk-coin-evm": "^1.1.0",
8384
"@bitgo/sdk-coin-flr": "^1.3.2",
8485
"@bitgo/sdk-coin-hash": "^3.1.2",
8586
"@bitgo/sdk-coin-hbar": "^2.2.2",

modules/bitgo/src/v2/coinFactory.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import {
3030
SuiTokenConfig,
3131
AptTokenConfig,
3232
Sip10TokenConfig,
33+
CoinFeature,
3334
} from '@bitgo/statics';
3435
import {
3536
Ada,
@@ -71,6 +72,7 @@ import {
7172
Eth,
7273
Ethw,
7374
EthLikeCoin,
75+
EvmCoin,
7476
Flr,
7577
TethLikeCoin,
7678
FiatAED,
@@ -367,6 +369,12 @@ export function registerCoinConstructors(coinFactory: CoinFactory, coinMap: Coin
367369
coinFactory.register('zeta', Zeta.createInstance);
368370
coinFactory.register('zketh', Zketh.createInstance);
369371

372+
coins
373+
.filter((coin) => coin.features.includes(CoinFeature.SHARED_EVM_SDK))
374+
.forEach((coin) => {
375+
coinFactory.register(coin.name, EvmCoin.createInstance);
376+
});
377+
370378
const tokens = getFormattedTokens(coinMap);
371379

372380
Erc20Token.createTokenConstructors([...tokens.bitcoin.eth.tokens, ...tokens.testnet.eth.tokens]).forEach(
@@ -488,6 +496,10 @@ export function registerCoinConstructors(coinFactory: CoinFactory, coinMap: Coin
488496
}
489497

490498
export function getCoinConstructor(coinName: string): CoinConstructor | undefined {
499+
const evmCoins = coins.filter((coin) => coin.features.includes(CoinFeature.SHARED_EVM_SDK));
500+
if (evmCoins.has(coinName)) {
501+
return EvmCoin.createInstance;
502+
}
491503
switch (coinName) {
492504
case 'ada':
493505
return Ada.createInstance;

modules/bitgo/src/v2/coins/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import { Dot, Tdot } from '@bitgo/sdk-coin-dot';
2929
import { Eos, EosToken, Teos } from '@bitgo/sdk-coin-eos';
3030
import { Etc, Tetc } from '@bitgo/sdk-coin-etc';
3131
import { Erc20Token, Eth, Gteth, Hteth, Teth } from '@bitgo/sdk-coin-eth';
32+
import { EvmCoin } from '@bitgo/sdk-coin-evm';
3233
import { Flr, Tflr } from '@bitgo/sdk-coin-flr';
3334
import { Ethw } from '@bitgo/sdk-coin-ethw';
3435
import { EthLikeCoin, TethLikeCoin } from '@bitgo/sdk-coin-ethlike';
@@ -103,6 +104,7 @@ export { Erc20Token, Eth, Gteth, Hteth, Teth };
103104
export { Ethw };
104105
export { EthLikeCoin, TethLikeCoin };
105106
export { Etc, Tetc };
107+
export { EvmCoin };
106108
export { Flr, Tflr };
107109
export { Hash, Thash };
108110
export { Hbar, Thbar };

modules/bitgo/tsconfig.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,9 @@
152152
{
153153
"path": "../sdk-coin-ethw"
154154
},
155+
{
156+
"path": "../sdk-coin-evm"
157+
},
155158
{
156159
"path": "../sdk-coin-flr"
157160
},

0 commit comments

Comments
 (0)