|
| 1 | +import { coins, TaoTokenConfig, tokens } from '@bitgo/statics'; |
| 2 | +import { Tao } from './tao'; |
| 3 | +import { BitGoBase, CoinConstructor, NamedCoinConstructor } from '@bitgo/sdk-core'; |
| 4 | + |
| 5 | +export class TaoToken extends Tao { |
| 6 | + public readonly tokenConfig: TaoTokenConfig; |
| 7 | + |
| 8 | + constructor(bitgo: BitGoBase, tokenConfig: TaoTokenConfig) { |
| 9 | + const staticsCoin = tokenConfig.network === 'Mainnet' ? coins.get('tao') : coins.get('ttao'); |
| 10 | + super(bitgo, staticsCoin); |
| 11 | + this.tokenConfig = tokenConfig; |
| 12 | + } |
| 13 | + |
| 14 | + static createTokenConstructor(config: TaoTokenConfig): CoinConstructor { |
| 15 | + return (bitgo: BitGoBase) => new TaoToken(bitgo, config); |
| 16 | + } |
| 17 | + |
| 18 | + static createTokenConstructors( |
| 19 | + tokenConfigs: TaoTokenConfig[] = [...tokens.bitcoin.tao.tokens, ...tokens.testnet.tao.tokens] |
| 20 | + ): NamedCoinConstructor[] { |
| 21 | + const tokensCtors: NamedCoinConstructor[] = []; |
| 22 | + for (const token of tokenConfigs) { |
| 23 | + const tokenConstructor = TaoToken.createTokenConstructor(token); |
| 24 | + tokensCtors.push({ name: token.type, coinConstructor: tokenConstructor }); |
| 25 | + } |
| 26 | + return tokensCtors; |
| 27 | + } |
| 28 | + |
| 29 | + get name(): string { |
| 30 | + return this.tokenConfig.name; |
| 31 | + } |
| 32 | + |
| 33 | + get coin(): string { |
| 34 | + return this.tokenConfig.coin; |
| 35 | + } |
| 36 | + |
| 37 | + get network(): string { |
| 38 | + return this.tokenConfig.network; |
| 39 | + } |
| 40 | + |
| 41 | + get subnetId(): string { |
| 42 | + return this.tokenConfig.subnetId; |
| 43 | + } |
| 44 | + |
| 45 | + get decimalPlaces(): number { |
| 46 | + return this.tokenConfig.decimalPlaces; |
| 47 | + } |
| 48 | + |
| 49 | + getChain(): string { |
| 50 | + return this.tokenConfig.type; |
| 51 | + } |
| 52 | + |
| 53 | + getBaseChain(): string { |
| 54 | + return this.coin; |
| 55 | + } |
| 56 | + |
| 57 | + getFullName(): string { |
| 58 | + return this._staticsCoin.fullName; |
| 59 | + } |
| 60 | + |
| 61 | + getBaseFactor(): number { |
| 62 | + return Math.pow(10, this.tokenConfig.decimalPlaces); |
| 63 | + } |
| 64 | +} |
0 commit comments