Skip to content

Commit 25cc4fe

Browse files
feat(sdk-api): add registerWithBaseCoin for dynamic token registration
TICKET: CSHLD-24 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 4b63462 commit 25cc4fe

4 files changed

Lines changed: 19 additions & 1 deletion

File tree

modules/sdk-api/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
"dependencies": {
4343
"@bitgo/argon2": "^1.0.0",
4444
"@bitgo/sdk-core": "^36.40.0",
45+
"@bitgo/statics": "^58.35.0",
4546
"io-ts": "npm:@bitgo-forks/io-ts@2.1.4",
4647
"@bitgo/sdk-hmac": "^1.9.0",
4748
"@bitgo/sjcl": "^1.1.0",

modules/sdk-api/src/bitgoAPI.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
makeRandomKey,
2323
sanitizeLegacyPath,
2424
} from '@bitgo/sdk-core';
25+
import { BaseCoin as StaticsBaseCoin } from '@bitgo/statics';
2526
import * as sdkHmac from '@bitgo/sdk-hmac';
2627
import { DefaultHmacAuthStrategy, type IHmacAuthStrategy } from '@bitgo/sdk-hmac';
2728
import * as utxolib from '@bitgo/utxo-lib';
@@ -1582,6 +1583,11 @@ export class BitGoAPI implements BitGoBase {
15821583
GlobalCoinFactory.register(name, coin);
15831584
}
15841585

1586+
public registerWithBaseCoin(name: string, coin: CoinConstructor, baseCoin: Readonly<StaticsBaseCoin>): void {
1587+
GlobalCoinFactory.register(name, coin);
1588+
GlobalCoinFactory.registerToken(baseCoin, coin);
1589+
}
1590+
15851591
/**
15861592
* Get bitcoin market data
15871593
*

modules/sdk-coin-eth/src/register.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,16 @@ export const register = (sdk: BitGoBase): void => {
2121
};
2222

2323
export const registerWithCoinMap = (sdk: BitGoBase, coinMap: CoinMap): void => {
24-
Erc20Token.createTokenConstructors(getFormattedErc20Tokens(coinMap)).forEach(({ name, coinConstructor }) => {
24+
sdk.register('eth', Eth.createInstance);
25+
sdk.register('gteth', Gteth.createInstance);
26+
sdk.register('teth', Teth.createInstance);
27+
sdk.register('hteth', Hteth.createInstance);
28+
Erc721Token.createTokenConstructors().forEach(({ name, coinConstructor }) => {
2529
sdk.register(name, coinConstructor);
2630
});
31+
32+
// Registration for dynamic ERC20 tokens that are not hardcoded in the SDK, but are present in the coin map generated using AMS.
33+
Erc20Token.createTokenConstructors(getFormattedErc20Tokens(coinMap)).forEach(({ name, coinConstructor }) => {
34+
sdk.registerWithBaseCoin(name, coinConstructor, coinMap.get(name));
35+
});
2736
};

modules/sdk-core/src/bitgo/bitgoBase.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
GetSharingKeyOptions,
77
IRequestTracer,
88
} from '../api';
9+
import { BaseCoin as StaticsBaseCoin } from '@bitgo/statics';
910
import { IBaseCoin } from './baseCoin';
1011
import { CoinConstructor } from './coinFactory';
1112
import { EnvironmentName } from './environments';
@@ -35,4 +36,5 @@ export interface BitGoBase {
3536
setRequestTracer(reqTracer: IRequestTracer): void;
3637
url(path: string, version?: number): string;
3738
register(name: string, coin: CoinConstructor): void;
39+
registerWithBaseCoin(name: string, coin: CoinConstructor, baseCoin: Readonly<StaticsBaseCoin>): void;
3840
}

0 commit comments

Comments
 (0)