Skip to content

Commit 1f8ffc3

Browse files
committed
fix: add xdc token contructor
Ticket: COIN-7060
1 parent cc49225 commit 1f8ffc3

File tree

3 files changed

+89
-0
lines changed

3 files changed

+89
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
import { BitGoBase } from '@bitgo/sdk-core';
22
import { Xdc } from './xdc';
33
import { Txdc } from './txdc';
4+
import { XdcToken } from './xdcToken';
45

56
export const register = (sdk: BitGoBase): void => {
67
sdk.register('xdc', Xdc.createInstance);
78
sdk.register('txdc', Txdc.createInstance);
9+
XdcToken.createTokenConstructors().forEach(({ name, coinConstructor }) => {
10+
sdk.register(name, coinConstructor);
11+
});
812
};
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/**
2+
* @prettier
3+
*/
4+
import { EthLikeTokenConfig, coins } from '@bitgo/statics';
5+
import { BitGoBase, CoinConstructor, NamedCoinConstructor, common, MPCAlgorithm } from '@bitgo/sdk-core';
6+
import { CoinNames, EthLikeToken, recoveryBlockchainExplorerQuery } from '@bitgo/abstract-eth';
7+
8+
import { TransactionBuilder } from './lib';
9+
export { EthLikeTokenConfig };
10+
11+
export class XdcToken extends EthLikeToken {
12+
public readonly tokenConfig: EthLikeTokenConfig;
13+
static coinNames: CoinNames = {
14+
Mainnet: 'xdc',
15+
Testnet: 'txdc',
16+
};
17+
constructor(bitgo: BitGoBase, tokenConfig: EthLikeTokenConfig) {
18+
super(bitgo, tokenConfig, XdcToken.coinNames);
19+
}
20+
static createTokenConstructor(config: EthLikeTokenConfig): CoinConstructor {
21+
return super.createTokenConstructor(config, XdcToken.coinNames);
22+
}
23+
24+
static createTokenConstructors(): NamedCoinConstructor[] {
25+
return super.createTokenConstructors(XdcToken.coinNames);
26+
}
27+
28+
protected getTransactionBuilder(): TransactionBuilder {
29+
return new TransactionBuilder(coins.get(this.getBaseChain()));
30+
}
31+
32+
/**
33+
* Make a query to XDC Etherscan for information such as balance, token balance, solidity calls
34+
* @param {Object} query key-value pairs of parameters to append after /api
35+
* @returns {Promise<Object>} response from XDC Etherscan
36+
*/
37+
async recoveryBlockchainExplorerQuery(query: Record<string, string>): Promise<Record<string, unknown>> {
38+
const apiToken = common.Environments[this.bitgo.getEnv()].xdcExplorerApiToken;
39+
const explorerUrl = common.Environments[this.bitgo.getEnv()].xdcExplorerBaseUrl;
40+
return await recoveryBlockchainExplorerQuery(query, explorerUrl as string, apiToken);
41+
}
42+
43+
getFullName(): string {
44+
return 'XDC Token';
45+
}
46+
47+
supportsTss(): boolean {
48+
return true;
49+
}
50+
51+
/** @inheritDoc */
52+
getMPCAlgorithm(): MPCAlgorithm {
53+
return 'ecdsa';
54+
}
55+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import 'should';
2+
import { TestBitGo, TestBitGoAPI } from '@bitgo/sdk-test';
3+
import { BitGoAPI } from '@bitgo/sdk-api';
4+
5+
import { register } from '../../src';
6+
7+
describe('XDC Token:', function () {
8+
let bitgo: TestBitGoAPI;
9+
let xdcTokenCoin;
10+
const tokenName = 'xdc:usdc';
11+
12+
before(function () {
13+
bitgo = TestBitGo.decorate(BitGoAPI, { env: 'prod' });
14+
register(bitgo);
15+
bitgo.initializeTestVars();
16+
xdcTokenCoin = bitgo.coin(tokenName);
17+
});
18+
19+
it('should return constants', function () {
20+
xdcTokenCoin.getChain().should.equal('xdc:usdc');
21+
xdcTokenCoin.getBaseChain().should.equal('xdc');
22+
xdcTokenCoin.getFullName().should.equal('XDC Token');
23+
xdcTokenCoin.getBaseFactor().should.equal(1e6);
24+
xdcTokenCoin.type.should.equal(tokenName);
25+
xdcTokenCoin.name.should.equal('USD Coin');
26+
xdcTokenCoin.coin.should.equal('xdc');
27+
xdcTokenCoin.network.should.equal('Mainnet');
28+
xdcTokenCoin.decimalPlaces.should.equal(6);
29+
});
30+
});

0 commit comments

Comments
 (0)