Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions modules/bitgo/src/v2/coinFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ import {
World,
WorldToken,
Xdc,
XdcToken,
Xlm,
Xrp,
XrpToken,
Expand Down Expand Up @@ -556,6 +557,10 @@ export function registerCoinConstructors(coinFactory: CoinFactory, coinMap: Coin
coinFactory.register(name, coinConstructor);
});

XdcToken.createTokenConstructors().forEach(({ name, coinConstructor }) => {
coinFactory.register(name, coinConstructor);
});

// Generic ERC20 token registration for coins with SUPPORTS_ERC20 feature
coins
.filter((coin) => coin.features.includes(CoinFeature.SUPPORTS_ERC20) && !coin.isToken)
Expand Down Expand Up @@ -1081,10 +1086,8 @@ export function getTokenConstructor(tokenConfig: TokenConfig): CoinConstructor |
return EthLikeErc20Token.createTokenConstructor(tokenConfig as EthLikeTokenConfig, coinNames);
}
case 'xdc':
case 'txdc': {
const coinNames = { Mainnet: 'xdc', Testnet: 'txdc' };
return EthLikeErc20Token.createTokenConstructor(tokenConfig as EthLikeTokenConfig, coinNames);
}
case 'txdc':
return XdcToken.createTokenConstructor(tokenConfig as EthLikeTokenConfig);
default:
return undefined;
}
Expand Down
4 changes: 2 additions & 2 deletions modules/bitgo/src/v2/coins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ import { StellarToken, Txlm, Xlm } from '@bitgo/sdk-coin-xlm';
import { Vet, Tvet, VetToken } from '@bitgo/sdk-coin-vet';
import { Wemix, Twemix } from '@bitgo/sdk-coin-wemix';
import { World, Tworld, WorldToken } from '@bitgo/sdk-coin-world';
import { Xdc, Txdc } from '@bitgo/sdk-coin-xdc';
import { Xdc, Txdc, XdcToken } from '@bitgo/sdk-coin-xdc';
import { Txrp, Xrp, XrpToken } from '@bitgo/sdk-coin-xrp';
import { Txtz, Xtz } from '@bitgo/sdk-coin-xtz';
import { Tzec, Zec } from '@bitgo/sdk-coin-zec';
Expand Down Expand Up @@ -142,7 +142,7 @@ export { Injective, Tinjective };
export { Islm, Tislm };
export { Trx, Ttrx };
export { Vet, Tvet, VetToken };
export { Xdc, Txdc };
export { Xdc, Txdc, XdcToken };
export { StellarToken, Txlm, Xlm };
export { Txrp, Xrp, XrpToken };
export { Txtz, Xtz };
Expand Down
1 change: 1 addition & 0 deletions modules/bitgo/test/browser/browser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ describe('Coins', () => {
EthLikeErc721Token: 1,
HashToken: 1,
FlrToken: 1,
XdcToken: 1,
JettonToken: 1,
};
Object.keys(BitGoJS.Coin)
Expand Down
1 change: 0 additions & 1 deletion modules/sdk-coin-xdc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
"@bitgo/abstract-eth": "^24.19.4",
"@bitgo/sdk-core": "^36.25.0",
"@bitgo/statics": "^58.19.0",
"@bitgo/sdk-coin-evm": "^1.11.0",
"@ethereumjs/common": "^2.6.5",
"@ethereumjs/tx": "^3.3.0"
},
Expand Down
1 change: 1 addition & 0 deletions modules/sdk-coin-xdc/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export * from './lib';
export * from './xdc';
export * from './txdc';
export * from './register';
export * from './xdcToken';
7 changes: 2 additions & 5 deletions modules/sdk-coin-xdc/src/register.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import { BitGoBase } from '@bitgo/sdk-core';
import { EthLikeErc20Token } from '@bitgo/sdk-coin-evm';
import { Xdc } from './xdc';
import { Txdc } from './txdc';
import { XdcToken } from './xdcToken';

export const register = (sdk: BitGoBase): void => {
sdk.register('xdc', Xdc.createInstance);
sdk.register('txdc', Txdc.createInstance);
EthLikeErc20Token.createTokenConstructors({
Mainnet: 'xdc',
Testnet: 'txdc',
}).forEach(({ name, coinConstructor }) => {
XdcToken.createTokenConstructors().forEach(({ name, coinConstructor }) => {
sdk.register(name, coinConstructor);
});
};
55 changes: 55 additions & 0 deletions modules/sdk-coin-xdc/src/xdcToken.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**
* @prettier
*/
import { EthLikeTokenConfig, coins } from '@bitgo/statics';
import { BitGoBase, CoinConstructor, NamedCoinConstructor, common, MPCAlgorithm } from '@bitgo/sdk-core';
import { CoinNames, EthLikeToken, recoveryBlockchainExplorerQuery } from '@bitgo/abstract-eth';

import { TransactionBuilder } from './lib';
export { EthLikeTokenConfig };

export class XdcToken extends EthLikeToken {
public readonly tokenConfig: EthLikeTokenConfig;
static coinNames: CoinNames = {
Mainnet: 'xdc',
Testnet: 'txdc',
};
constructor(bitgo: BitGoBase, tokenConfig: EthLikeTokenConfig) {
super(bitgo, tokenConfig, XdcToken.coinNames);
}
static createTokenConstructor(config: EthLikeTokenConfig): CoinConstructor {
return super.createTokenConstructor(config, XdcToken.coinNames);
}

static createTokenConstructors(): NamedCoinConstructor[] {
return super.createTokenConstructors(XdcToken.coinNames);
}

protected getTransactionBuilder(): TransactionBuilder {
return new TransactionBuilder(coins.get(this.getBaseChain()));
}

/**
* Make a query to XDC Etherscan for information such as balance, token balance, solidity calls
* @param {Object} query key-value pairs of parameters to append after /api
* @returns {Promise<Object>} response from XDC Etherscan
*/
async recoveryBlockchainExplorerQuery(query: Record<string, string>): Promise<Record<string, unknown>> {
const apiToken = common.Environments[this.bitgo.getEnv()].xdcExplorerApiToken;
const explorerUrl = common.Environments[this.bitgo.getEnv()].xdcExplorerBaseUrl;
return await recoveryBlockchainExplorerQuery(query, explorerUrl as string, apiToken);
}

getFullName(): string {
return 'XDC Token';
}

supportsTss(): boolean {
return true;
}

/** @inheritDoc */
getMPCAlgorithm(): MPCAlgorithm {
return 'ecdsa';
}
}
2 changes: 1 addition & 1 deletion modules/sdk-coin-xdc/test/unit/xdcToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('XDC Token:', function () {
it('should return constants', function () {
xdcTokenCoin.getChain().should.equal('xdc:usdc');
xdcTokenCoin.getBaseChain().should.equal('xdc');
xdcTokenCoin.getFullName().should.equal('ERC20 Token');
xdcTokenCoin.getFullName().should.equal('XDC Token');
xdcTokenCoin.getBaseFactor().should.equal(1e6);
xdcTokenCoin.type.should.equal(tokenName);
xdcTokenCoin.name.should.equal('USD Coin');
Expand Down
100 changes: 100 additions & 0 deletions modules/statics/src/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,16 @@ export class FlrERC20Token extends ContractAddressDefinedToken {
}
}

/**
* The XDC network supports tokens
* XDC Tokens are ERC20 tokens
*/
export class XdcERC20Token extends ContractAddressDefinedToken {
constructor(options: Erc20ConstructorOptions) {
super(options);
}
}

/**
* The Xrp network supports tokens
* Xrp tokens are identified by their issuer address
Expand Down Expand Up @@ -2856,6 +2866,96 @@ export function tflrErc20(
);
}

/**
* Factory function for XdcErc20 token instances.
*
* @param id uuid v4
* @param name unique identifier of the token
* @param fullName Complete human-readable name of the token
* @param decimalPlaces Number of decimal places this token supports (divisibility exponent)
* @param contractAddress Contract address of this token
* @param asset Asset which this coin represents. This is the same for both mainnet and testnet variants of a coin.
* @param prefix? Optional token prefix. Defaults to empty string
* @param suffix? Optional token suffix. Defaults to token name.
* @param network? Optional token network. Defaults to XDC mainnet network.
* @param features? Features of this coin. Defaults to the DEFAULT_FEATURES defined in `AccountCoin`
* @param primaryKeyCurve The elliptic curve for this chain/token
*/
export function xdcErc20(
id: string,
name: string,
fullName: string,
decimalPlaces: number,
contractAddress: string,
asset: UnderlyingAsset,
features: CoinFeature[] = [...AccountCoin.DEFAULT_FEATURES, CoinFeature.EIP1559],
prefix = '',
suffix: string = name.toUpperCase(),
network: AccountNetwork = Networks.main.xdc,
primaryKeyCurve: KeyCurve = KeyCurve.Secp256k1
) {
return Object.freeze(
new XdcERC20Token({
id,
name,
fullName,
network,
contractAddress,
prefix,
suffix,
features,
decimalPlaces,
asset,
isToken: true,
primaryKeyCurve,
baseUnit: BaseUnit.ETH,
})
);
}

/**
* Factory function for XDC testnet XdcErc20 token instances.
*
* @param id uuid v4
* @param name unique identifier of the token
* @param fullName Complete human-readable name of the token
* @param decimalPlaces Number of decimal places this token supports (divisibility exponent)
* @param contractAddress Contract address of this token
* @param asset Asset which this coin represents. This is the same for both mainnet and testnet variants of a coin.
* @param prefix? Optional token prefix. Defaults to empty string
* @param suffix? Optional token suffix. Defaults to token name.
* @param network? Optional token network. Defaults to the XDC test network.
* @param features? Features of this coin. Defaults to the DEFAULT_FEATURES defined in `AccountCoin`
* @param primaryKeyCurve The elliptic curve for this chain/token
*/
export function txdcErc20(
id: string,
name: string,
fullName: string,
decimalPlaces: number,
contractAddress: string,
asset: UnderlyingAsset,
features: CoinFeature[] = AccountCoin.DEFAULT_FEATURES,
prefix = '',
suffix: string = name.toUpperCase(),
network: AccountNetwork = Networks.test.xdc,
primaryKeyCurve: KeyCurve = KeyCurve.Secp256k1
) {
return xdcErc20(
id,
name,
fullName,
decimalPlaces,
contractAddress,
asset,
features,
prefix,
suffix,
network,
primaryKeyCurve
);
}

/**
* Factory function for xrp token instances.
*
Expand Down
32 changes: 14 additions & 18 deletions modules/statics/src/allCoinsAndTokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
erc721Token,
fiat,
flrErc20,
xdcErc20,
gasTankAccount,
hederaCoin,
hederaToken,
Expand All @@ -34,6 +35,7 @@ import {
terc1155,
terc721,
tflrErc20,
txdcErc20,
topethErc20,
tronToken,
tstellarToken,
Expand Down Expand Up @@ -2980,61 +2982,55 @@ export const allCoinsAndTokens = [
),

// XDC mainnet tokens
erc20Token(
xdcErc20(
'b820932d-5772-49ae-a055-a59760f3e4cf',
'xdc:usdc',
'USD Coin',
6,
'0xfa2958cb79b0491cc627c1557f441ef849ca8eb1',
UnderlyingAsset['xdc:usdc'],
Networks.main.xdc
UnderlyingAsset['xdc:usdc']
),
erc20Token(
xdcErc20(
'8914a1bd-1495-46df-84da-445c6d49edb2',
'xdc:lbt',
'Law Block Token',
18,
'0x05940b2df33d6371201e7ae099ced4c363855dfe',
UnderlyingAsset['xdc:lbt'],
Networks.main.xdc
UnderlyingAsset['xdc:lbt']
),
erc20Token(
xdcErc20(
'f03302de-b06b-4ddc-94a2-ad7e89896725',
'xdc:gama',
'Gama Token',
18,
'0x3a170c7c987f55c84f28733bfa27962d8cdd5d3b',
UnderlyingAsset['xdc:gama'],
Networks.main.xdc
UnderlyingAsset['xdc:gama']
),
erc20Token(
xdcErc20(
'bdf602ea-3a6c-407a-8afd-33d6c04a8bc3',
'xdc:srx',
'STORX',
18,
'0x5d5f074837f5d4618b3916ba74de1bf9662a3fed',
UnderlyingAsset['xdc:srx'],
Networks.main.xdc
UnderlyingAsset['xdc:srx']
),
erc20Token(
xdcErc20(
'd42c9497-0987-497d-97f2-8b19c539e350',
'xdc:weth',
'Wrapped Ether',
18,
'0xa7348290de5cf01772479c48d50dec791c3fc212',
UnderlyingAsset['xdc:weth'],
Networks.main.xdc
UnderlyingAsset['xdc:weth']
),

// XDC testnet tokens
erc20Token(
txdcErc20(
'5fc561e7-5fb5-4702-9860-9f48d90f1d45',
'txdc:tmt',
'XDC Network TMT',
6,
'0xb283ec8dad644effc5c4c50bb7bb21442ac3c2db',
UnderlyingAsset['txdc:tmt'],
Networks.test.xdc
UnderlyingAsset['txdc:tmt']
),

// MON mainnet tokens
Expand Down
6 changes: 1 addition & 5 deletions modules/statics/src/coinFeatures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -692,11 +692,7 @@ export const VET_TOKEN_FEATURES = VET_FEATURES.filter((feature) => feature !== C

export const EVM_NON_EIP1559_FEATURES = [...EVM_FEATURES.filter((feature) => feature !== CoinFeature.EIP1559)];

export const XDC_FEATURES = [
...EVM_NON_EIP1559_FEATURES,
CoinFeature.ERC20_BULK_TRANSACTION,
CoinFeature.SUPPORTS_ERC20,
];
export const XDC_FEATURES = [...EVM_NON_EIP1559_FEATURES, CoinFeature.ERC20_BULK_TRANSACTION];

export const SGB_FEATURES = [...EVM_FEATURES, CoinFeature.ERC20_BULK_TRANSACTION];

Expand Down
Loading