|
| 1 | +/** |
| 2 | + * @prettier |
| 3 | + */ |
| 4 | +import { coins, EthLikeTokenConfig } from '@bitgo/statics'; |
| 5 | +import { BitGoBase, CoinConstructor, common, MPCAlgorithm, NamedCoinConstructor } from '@bitgo/sdk-core'; |
| 6 | +import { CoinNames, EthLikeToken, recoveryBlockchainExplorerQuery } from '@bitgo/abstract-eth'; |
| 7 | +import { TransactionBuilder } from './lib'; |
| 8 | +import assert from 'assert'; |
| 9 | + |
| 10 | +export class EthLikeErc20Token extends EthLikeToken { |
| 11 | + public readonly tokenConfig: EthLikeTokenConfig; |
| 12 | + private readonly coinNames: CoinNames; |
| 13 | + |
| 14 | + constructor(bitgo: BitGoBase, tokenConfig: EthLikeTokenConfig, coinNames: CoinNames) { |
| 15 | + super(bitgo, tokenConfig, coinNames); |
| 16 | + this.coinNames = coinNames; |
| 17 | + } |
| 18 | + |
| 19 | + static createTokenConstructor(config: EthLikeTokenConfig, coinNames: CoinNames): CoinConstructor { |
| 20 | + return (bitgo: BitGoBase) => new this(bitgo, config, coinNames); |
| 21 | + } |
| 22 | + |
| 23 | + static createTokenConstructors(coinNames: CoinNames): NamedCoinConstructor[] { |
| 24 | + return super.createTokenConstructors(coinNames); |
| 25 | + } |
| 26 | + |
| 27 | + protected getTransactionBuilder(): TransactionBuilder { |
| 28 | + return new TransactionBuilder(coins.get(this.getBaseChain())); |
| 29 | + } |
| 30 | + |
| 31 | + getMPCAlgorithm(): MPCAlgorithm { |
| 32 | + return 'ecdsa'; |
| 33 | + } |
| 34 | + |
| 35 | + supportsTss(): boolean { |
| 36 | + return true; |
| 37 | + } |
| 38 | + |
| 39 | + async recoveryBlockchainExplorerQuery(query: Record<string, string>): Promise<Record<string, unknown>> { |
| 40 | + const family = this.getFamily(); |
| 41 | + const evmConfig = common.Environments[this.bitgo.getEnv()].evm; |
| 42 | + assert( |
| 43 | + evmConfig && this.getFamily() in evmConfig, |
| 44 | + `env config is missing for ${this.getFamily()} in ${this.bitgo.getEnv()}` |
| 45 | + ); |
| 46 | + const explorerUrl = evmConfig[family].baseUrl; |
| 47 | + const apiToken = evmConfig[family].apiToken; |
| 48 | + return await recoveryBlockchainExplorerQuery(query, explorerUrl as string, apiToken); |
| 49 | + } |
| 50 | + |
| 51 | + //TODO: implement a way to return the coin family name or coin name instead of standard ERC20 Token. |
| 52 | + getFullName(): string { |
| 53 | + return 'ERC20 Token'; |
| 54 | + } |
| 55 | +} |
0 commit comments