-
Notifications
You must be signed in to change notification settings - Fork 283
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5426 from BitGo/COIN-2889-apt-token-skeleton
feat(sdk-coin-apt): add Apt Token Skeleton
- Loading branch information
Showing
5 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { Apt } from './apt'; | ||
import { BitGoBase, CoinConstructor, NamedCoinConstructor } from '@bitgo/sdk-core'; | ||
import { AptTokenConfig, coins, tokens } from '@bitgo/statics'; | ||
|
||
export class AptToken extends Apt { | ||
public readonly tokenConfig: AptTokenConfig; | ||
|
||
constructor(bitgo: BitGoBase, tokenConfig: AptTokenConfig) { | ||
const staticsCoin = tokenConfig.network === 'Mainnet' ? coins.get('apt') : coins.get('tapt'); | ||
super(bitgo, staticsCoin); | ||
this.tokenConfig = tokenConfig; | ||
} | ||
|
||
static createTokenConstructor(config: AptTokenConfig): CoinConstructor { | ||
return (bitgo: BitGoBase) => new AptToken(bitgo, config); | ||
} | ||
|
||
static createTokenConstructors(): NamedCoinConstructor[] { | ||
const tokensCtors: NamedCoinConstructor[] = []; | ||
for (const token of [...tokens.bitcoin.apt.tokens, ...tokens.testnet.apt.tokens]) { | ||
const tokenConstructor = AptToken.createTokenConstructor(token); | ||
tokensCtors.push({ name: token.type, coinConstructor: tokenConstructor }); | ||
} | ||
return tokensCtors; | ||
} | ||
|
||
get name(): string { | ||
return this.tokenConfig.name; | ||
} | ||
|
||
get coin(): string { | ||
return this.tokenConfig.coin; | ||
} | ||
|
||
get network(): string { | ||
return this.tokenConfig.network; | ||
} | ||
|
||
get fungibleAssestAddress(): string { | ||
return this.tokenConfig.fungibleAssetAddress; | ||
} | ||
|
||
get decimalPlaces(): number { | ||
return this.tokenConfig.decimalPlaces; | ||
} | ||
|
||
getChain(): string { | ||
return this.tokenConfig.type; | ||
} | ||
|
||
getBaseChain(): string { | ||
return this.coin; | ||
} | ||
|
||
getFullName(): string { | ||
return 'Apt Token'; | ||
} | ||
|
||
getBaseFactor(): number { | ||
return Math.pow(10, this.tokenConfig.decimalPlaces); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,12 @@ | ||
import { BitGoBase } from '@bitgo/sdk-core'; | ||
import { Apt } from './apt'; | ||
import { Tapt } from './tapt'; | ||
import { AptToken } from './aptToken'; | ||
|
||
export const register = (sdk: BitGoBase): void => { | ||
sdk.register('apt', Apt.createInstance); | ||
sdk.register('tapt', Tapt.createInstance); | ||
AptToken.createTokenConstructors().forEach(({ name, coinConstructor }) => { | ||
sdk.register(name, coinConstructor); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,5 +20,6 @@ export { | |
TronErc20Coin, | ||
SuiCoin, | ||
XrpCoin, | ||
AptCoin, | ||
} from './account'; | ||
export { CoinMap } from './map'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters