|
| 1 | +/** |
| 2 | + * @prettier |
| 3 | + */ |
| 4 | +import { BaseCoin, BitGoBase, common, MPCAlgorithm, MultisigType, multisigTypes } from '@bitgo/sdk-core'; |
| 5 | +import { BaseCoin as StaticsBaseCoin, CoinFeature, coins } from '@bitgo/statics'; |
| 6 | +import { |
| 7 | + AbstractEthLikeNewCoins, |
| 8 | + OfflineVaultTxInfo, |
| 9 | + RecoverOptions, |
| 10 | + recoveryBlockchainExplorerQuery, |
| 11 | + TransactionBuilder as EthLikeTransactionBuilder, |
| 12 | + UnsignedSweepTxMPCv2, |
| 13 | +} from '@bitgo/abstract-eth'; |
| 14 | +import { TransactionBuilder } from './lib'; |
| 15 | +import assert from 'assert'; |
| 16 | + |
| 17 | +export class EvmCoin extends AbstractEthLikeNewCoins { |
| 18 | + protected constructor(bitgo: BitGoBase, staticsCoin?: Readonly<StaticsBaseCoin>) { |
| 19 | + super(bitgo, staticsCoin); |
| 20 | + } |
| 21 | + |
| 22 | + static createInstance(bitgo: BitGoBase, staticsCoin?: Readonly<StaticsBaseCoin>): BaseCoin { |
| 23 | + return new EvmCoin(bitgo, staticsCoin); |
| 24 | + } |
| 25 | + |
| 26 | + protected getTransactionBuilder(): EthLikeTransactionBuilder { |
| 27 | + return new TransactionBuilder(coins.get(this.getBaseChain())); |
| 28 | + } |
| 29 | + |
| 30 | + /** @inheritDoc */ |
| 31 | + supportsTss(): boolean { |
| 32 | + return this.staticsCoin?.features.includes(CoinFeature.TSS) ?? false; |
| 33 | + } |
| 34 | + |
| 35 | + /** inherited doc */ |
| 36 | + getDefaultMultisigType(): MultisigType { |
| 37 | + return this.staticsCoin?.features.includes(CoinFeature.TSS) ? multisigTypes.tss : multisigTypes.onchain; |
| 38 | + } |
| 39 | + |
| 40 | + /** @inheritDoc */ |
| 41 | + getMPCAlgorithm(): MPCAlgorithm { |
| 42 | + return 'ecdsa'; |
| 43 | + } |
| 44 | + |
| 45 | + protected async buildUnsignedSweepTxnTSS(params: RecoverOptions): Promise<OfflineVaultTxInfo | UnsignedSweepTxMPCv2> { |
| 46 | + if (this.staticsCoin?.features.includes(CoinFeature.MPCV2)) { |
| 47 | + return this.buildUnsignedSweepTxnMPCv2(params); |
| 48 | + } |
| 49 | + return super.buildUnsignedSweepTxnTSS(params); |
| 50 | + } |
| 51 | + |
| 52 | + /** |
| 53 | + * Make a query to chain explorer for information such as balance, token balance, solidity calls |
| 54 | + * @param {Object} query key-value pairs of parameters to append after /api |
| 55 | + * @returns {Promise<Object>} response from chain explorer |
| 56 | + */ |
| 57 | + async recoveryBlockchainExplorerQuery(query: Record<string, string>): Promise<Record<string, unknown>> { |
| 58 | + const evmConfig = common.Environments[this.bitgo.getEnv()].evm; |
| 59 | + assert( |
| 60 | + evmConfig && this.getFamily() in evmConfig, |
| 61 | + `env config is missing for ${this.getFamily()} in ${this.bitgo.getEnv()}` |
| 62 | + ); |
| 63 | + |
| 64 | + const apiToken = evmConfig[this.getFamily()].apiToken; |
| 65 | + const explorerUrl = evmConfig[this.getFamily()].baseUrl; |
| 66 | + return await recoveryBlockchainExplorerQuery(query, explorerUrl as string, apiToken as string); |
| 67 | + } |
| 68 | +} |
0 commit comments