Skip to content

Commit 1910925

Browse files
authored
Merge pull request #6111 from BitGo/WIN-5459_stcore
feat(sdk-coin-coredao): add coredao token support
2 parents e585e04 + 66378e5 commit 1910925

File tree

11 files changed

+253
-2
lines changed

11 files changed

+253
-2
lines changed

modules/bitgo/src/v2/coinFactory.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import {
3434
Celo,
3535
CeloToken,
3636
Coredao,
37+
CoredaoToken,
3738
Coreum,
3839
Cronos,
3940
Cspr,
@@ -405,6 +406,10 @@ export function registerCoinConstructors(coinFactory: CoinFactory, coinMap: Coin
405406
coinFactory.register(name, coinConstructor);
406407
});
407408

409+
CoredaoToken.createTokenConstructors().forEach(({ name, coinConstructor }) => {
410+
coinFactory.register(name, coinConstructor);
411+
});
412+
408413
SolToken.createTokenConstructors([...tokens.bitcoin.sol.tokens, ...tokens.testnet.sol.tokens]).forEach(
409414
({ name, coinConstructor }) => {
410415
coinFactory.register(name, coinConstructor);

modules/bitgo/src/v2/coins/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { Bsv, Tbsv } from '@bitgo/sdk-coin-bsv';
1717
import { Btc, Tbtc, Tbtcsig, Tbtc4, Tbtcbgsig } from '@bitgo/sdk-coin-btc';
1818
import { Btg } from '@bitgo/sdk-coin-btg';
1919
import { Celo, CeloToken, Tcelo } from '@bitgo/sdk-coin-celo';
20-
import { Coredao, Tcoredao } from '@bitgo/sdk-coin-coredao';
20+
import { Coredao, Tcoredao, CoredaoToken } from '@bitgo/sdk-coin-coredao';
2121
import { Coreum, Tcoreum } from '@bitgo/sdk-coin-coreum';
2222
import { Cronos, Tcronos } from '@bitgo/sdk-coin-cronos';
2323
import { Cspr, Tcspr } from '@bitgo/sdk-coin-cspr';
@@ -86,7 +86,7 @@ export { Bsv, Tbsv };
8686
export { Btc, Tbtc, Tbtcsig, Tbtc4, Tbtcbgsig };
8787
export { Btg };
8888
export { Celo, CeloToken, Tcelo };
89-
export { Coredao, Tcoredao };
89+
export { Coredao, Tcoredao, CoredaoToken };
9090
export { Coreum, Tcoreum };
9191
export { Cronos, Tcronos };
9292
export { Cspr, Tcspr };

modules/bitgo/test/browser/browser.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ describe('Coins', () => {
4242
SoneiumToken: 1,
4343
Polyx: 1,
4444
Tpolyx: 1,
45+
CoredaoToken: 1,
4546
};
4647
Object.keys(BitGoJS.Coin)
4748
.filter((coinName) => !excludedKeys[coinName])
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/**
2+
* @prettier
3+
*/
4+
import { coins, EthLikeTokenConfig } from '@bitgo/statics';
5+
import { BitGoBase, CoinConstructor, common, MPCAlgorithm, NamedCoinConstructor } from '@bitgo/sdk-core';
6+
import { CoinNames, EthLikeToken, recoveryBlockchainExplorerQuery } from '@bitgo/abstract-eth';
7+
8+
import { TransactionBuilder } from './lib';
9+
10+
export { EthLikeTokenConfig };
11+
12+
export class CoredaoToken extends EthLikeToken {
13+
public readonly tokenConfig: EthLikeTokenConfig;
14+
static coinNames: CoinNames = {
15+
Mainnet: 'coredao',
16+
Testnet: 'tcoredao',
17+
};
18+
constructor(bitgo: BitGoBase, tokenConfig: EthLikeTokenConfig) {
19+
super(bitgo, tokenConfig, CoredaoToken.coinNames);
20+
}
21+
static createTokenConstructor(config: EthLikeTokenConfig): CoinConstructor {
22+
return super.createTokenConstructor(config, CoredaoToken.coinNames);
23+
}
24+
25+
static createTokenConstructors(): NamedCoinConstructor[] {
26+
return super.createTokenConstructors(CoredaoToken.coinNames);
27+
}
28+
29+
protected getTransactionBuilder(): TransactionBuilder {
30+
return new TransactionBuilder(coins.get(this.getBaseChain()));
31+
}
32+
33+
/** @inheritDoc **/
34+
getMPCAlgorithm(): MPCAlgorithm {
35+
return 'ecdsa';
36+
}
37+
38+
/** @inheritDoc */
39+
supportsTss(): boolean {
40+
return true;
41+
}
42+
43+
/**
44+
* Make a query to Coredao explorer for information such as balance, token balance, solidity calls
45+
* @param {Object} query key-value pairs of parameters to append after /api
46+
* @returns {Promise<Object>} response Coredao explorer
47+
*/
48+
async recoveryBlockchainExplorerQuery(query: Record<string, string>): Promise<Record<string, unknown>> {
49+
const apiToken = common.Environments[this.bitgo.getEnv()].coredaoExplorerApiToken;
50+
const explorerUrl = common.Environments[this.bitgo.getEnv()].coredaoExplorerBaseUrl;
51+
return await recoveryBlockchainExplorerQuery(query, explorerUrl as string, apiToken);
52+
}
53+
54+
getFullName(): string {
55+
return 'Coredao Token';
56+
}
57+
}

modules/sdk-coin-coredao/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export * from './lib';
22
export * from './coredao';
33
export * from './tcoredao';
4+
export * from './coredaoToken';
45
export * from './register';
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 { Coredao } from './coredao';
33
import { Tcoredao } from './tcoredao';
4+
import { CoredaoToken } from './coredaoToken';
45

56
export const register = (sdk: BitGoBase): void => {
67
sdk.register('coredao', Coredao.createInstance);
78
sdk.register('tcoredao', Tcoredao.createInstance);
9+
CoredaoToken.createTokenConstructors().forEach(({ name, coinConstructor }) => {
10+
sdk.register(name, coinConstructor);
11+
});
812
};
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { TestBitGo, TestBitGoAPI } from '@bitgo/sdk-test';
2+
import { BitGoAPI } from '@bitgo/sdk-api';
3+
4+
import { CoredaoToken } from '../../src';
5+
6+
describe('Coredao Token:', function () {
7+
let bitgo: TestBitGoAPI;
8+
let coredaoTokenCoin;
9+
const tokenName = 'tcoredao:stcore';
10+
11+
before(function () {
12+
bitgo = TestBitGo.decorate(BitGoAPI, { env: 'test' });
13+
CoredaoToken.createTokenConstructors().forEach(({ name, coinConstructor }) => {
14+
bitgo.safeRegister(name, coinConstructor);
15+
});
16+
bitgo.initializeTestVars();
17+
coredaoTokenCoin = bitgo.coin(tokenName);
18+
});
19+
20+
it('should return constants', function () {
21+
coredaoTokenCoin.getChain().should.equal('tcoredao:stcore');
22+
coredaoTokenCoin.getBaseChain().should.equal('tcoredao');
23+
coredaoTokenCoin.getFullName().should.equal('Coredao Token');
24+
coredaoTokenCoin.getBaseFactor().should.equal(1e18);
25+
coredaoTokenCoin.type.should.equal(tokenName);
26+
coredaoTokenCoin.name.should.equal('Testnet stCore token');
27+
coredaoTokenCoin.coin.should.equal('tcoredao');
28+
coredaoTokenCoin.network.should.equal('Testnet');
29+
coredaoTokenCoin.decimalPlaces.should.equal(18);
30+
});
31+
});

modules/statics/src/account.ts

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,16 @@ export class BeraERC20Token extends ContractAddressDefinedToken {
461461
}
462462
}
463463

464+
/**
465+
* The Coredao Chain network support tokens
466+
* Coredao Chain Tokens are ERC20 tokens
467+
*/
468+
export class CoredaoERC20Token extends ContractAddressDefinedToken {
469+
constructor(options: Erc20ConstructorOptions) {
470+
super(options);
471+
}
472+
}
473+
464474
/**
465475
* The Xrp network supports tokens
466476
* Xrp tokens are identified by their issuer address
@@ -2280,6 +2290,96 @@ export function tberaErc20(
22802290
);
22812291
}
22822292

2293+
/**
2294+
* Factory function for CoredaoErc20 token instances.
2295+
*
2296+
* @param id uuid v4
2297+
* @param name unique identifier of the token
2298+
* @param fullName Complete human-readable name of the token
2299+
* @param decimalPlaces Number of decimal places this token supports (divisibility exponent)
2300+
* @param contractAddress Contract address of this token
2301+
* @param asset Asset which this coin represents. This is the same for both mainnet and testnet variants of a coin.
2302+
* @param prefix? Optional token prefix. Defaults to empty string
2303+
* @param suffix? Optional token suffix. Defaults to token name.
2304+
* @param network? Optional token network. Defaults to coredao mainnet network.
2305+
* @param features? Features of this coin. Defaults to the DEFAULT_FEATURES defined in `AccountCoin`
2306+
* @param primaryKeyCurve The elliptic curve for this chain/token
2307+
*/
2308+
export function coredaoErc20(
2309+
id: string,
2310+
name: string,
2311+
fullName: string,
2312+
decimalPlaces: number,
2313+
contractAddress: string,
2314+
asset: UnderlyingAsset,
2315+
features: CoinFeature[] = [...AccountCoin.DEFAULT_FEATURES, CoinFeature.EIP1559],
2316+
prefix = '',
2317+
suffix: string = name.toUpperCase(),
2318+
network: AccountNetwork = Networks.main.coredao,
2319+
primaryKeyCurve: KeyCurve = KeyCurve.Secp256k1
2320+
) {
2321+
return Object.freeze(
2322+
new CoredaoERC20Token({
2323+
id,
2324+
name,
2325+
fullName,
2326+
network,
2327+
contractAddress,
2328+
prefix,
2329+
suffix,
2330+
features,
2331+
decimalPlaces,
2332+
asset,
2333+
isToken: true,
2334+
primaryKeyCurve,
2335+
baseUnit: BaseUnit.ETH,
2336+
})
2337+
);
2338+
}
2339+
2340+
/**
2341+
* Factory function for coredao testnet coredaoErc20 token instances.
2342+
*
2343+
* @param id uuid v4
2344+
* @param name unique identifier of the token
2345+
* @param fullName Complete human-readable name of the token
2346+
* @param decimalPlaces Number of decimal places this token supports (divisibility exponent)
2347+
* @param contractAddress Contract address of this token
2348+
* @param asset Asset which this coin represents. This is the same for both mainnet and testnet variants of a coin.
2349+
* @param prefix? Optional token prefix. Defaults to empty string
2350+
* @param suffix? Optional token suffix. Defaults to token name.
2351+
* @param network? Optional token network. Defaults to the coredao test network.
2352+
* @param features? Features of this coin. Defaults to the DEFAULT_FEATURES defined in `AccountCoin`
2353+
* @param primaryKeyCurve The elliptic curve for this chain/token
2354+
*/
2355+
export function tcoredaoErc20(
2356+
id: string,
2357+
name: string,
2358+
fullName: string,
2359+
decimalPlaces: number,
2360+
contractAddress: string,
2361+
asset: UnderlyingAsset,
2362+
features: CoinFeature[] = AccountCoin.DEFAULT_FEATURES,
2363+
prefix = '',
2364+
suffix: string = name.toUpperCase(),
2365+
network: AccountNetwork = Networks.test.coredao,
2366+
primaryKeyCurve: KeyCurve = KeyCurve.Secp256k1
2367+
) {
2368+
return coredaoErc20(
2369+
id,
2370+
name,
2371+
fullName,
2372+
decimalPlaces,
2373+
contractAddress,
2374+
asset,
2375+
features,
2376+
prefix,
2377+
suffix,
2378+
network,
2379+
primaryKeyCurve
2380+
);
2381+
}
2382+
22832383
/**
22842384
* Factory function for xrp token instances.
22852385
*

modules/statics/src/base.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2438,6 +2438,12 @@ export enum UnderlyingAsset {
24382438
'erc721:soneiumtoken' = 'erc721:soneiumtoken',
24392439
'erc1155:soneiumtoken' = 'erc1155:soneiumtoken',
24402440

2441+
// coredao mainnet tokens
2442+
'coredao:stcore' = 'coredao:stcore',
2443+
2444+
// coredao testnet tokens
2445+
'tcoredao:stcore' = 'tcoredao:stcore',
2446+
24412447
ERC721 = 'erc721',
24422448
ERC1155 = 'erc1155',
24432449
NONSTANDARD = 'nonstandard',

modules/statics/src/coins.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
beraErc20,
1010
bscToken,
1111
celoToken,
12+
coredaoErc20,
1213
eosToken,
1314
erc1155,
1415
erc20,
@@ -31,6 +32,7 @@ import {
3132
tarbethErc20,
3233
tberaErc20,
3334
tceloToken,
35+
tcoredaoErc20,
3436
teosToken,
3537
terc1155,
3638
terc721,
@@ -2952,6 +2954,22 @@ export const coins = CoinMap.fromCoins([
29522954
'0x5bdc3cae6fb270ef07579c428bb630e73c8d623b',
29532955
UnderlyingAsset['tbera:ibera']
29542956
),
2957+
coredaoErc20(
2958+
'7dfd048f-7718-46e7-8cdb-864a3fc27b1b',
2959+
'coredao:stcore',
2960+
'stCore Token',
2961+
18,
2962+
'0xb3a8f0f0da9ffc65318aa39e55079796093029ad',
2963+
UnderlyingAsset['coredao:stcore']
2964+
),
2965+
tcoredaoErc20(
2966+
'b4448868-8beb-4dd8-b607-3b36e11f1df4',
2967+
'tcoredao:stcore',
2968+
'Testnet stCore token',
2969+
18,
2970+
'0x6401f24ef7c54032f4f54e67492928973ab87650',
2971+
UnderlyingAsset['tcoredao:stcore']
2972+
),
29552973
txrpToken(
29562974
'8ef16158-1015-4a67-b6fe-db669c18ab2b',
29572975
'txrp:tst-rP9jPyP5kyvFRb6ZiRghAGw5u8SGAmU4bd',

modules/statics/src/tokenConfig.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
BeraERC20Token,
99
BscCoin,
1010
CeloCoin,
11+
CoredaoERC20Token,
1112
EosCoin,
1213
Erc1155Coin,
1314
Erc20Coin,
@@ -143,6 +144,9 @@ export interface Tokens {
143144
opeth: {
144145
tokens: EthLikeTokenConfig[];
145146
};
147+
coredao: {
148+
tokens: EthLikeTokenConfig[];
149+
};
146150
sol: {
147151
tokens: SolTokenConfig[];
148152
};
@@ -236,6 +240,9 @@ export interface Tokens {
236240
bera: {
237241
tokens: EthLikeTokenConfig[];
238242
};
243+
coredao: {
244+
tokens: EthLikeTokenConfig[];
245+
};
239246
apt: {
240247
tokens: AptTokenConfig[];
241248
nftCollections: AptNFTCollectionConfig[];
@@ -516,6 +523,21 @@ const getFormattedBeraTokens = (customCoinMap = coins) =>
516523
return acc;
517524
}, []);
518525

526+
const getFormattedCoredaoTokens = (customCoinMap = coins) =>
527+
customCoinMap.reduce((acc: EthLikeTokenConfig[], coin) => {
528+
if (coin instanceof CoredaoERC20Token) {
529+
acc.push({
530+
type: coin.name,
531+
coin: coin.network.type === NetworkType.MAINNET ? 'coredao' : 'tcoredao',
532+
network: coin.network.type === NetworkType.MAINNET ? 'Mainnet' : 'Testnet',
533+
name: coin.fullName,
534+
tokenContractAddress: coin.contractAddress.toString().toLowerCase(),
535+
decimalPlaces: coin.decimalPlaces,
536+
});
537+
}
538+
return acc;
539+
}, []);
540+
519541
const getFormattedSolTokens = (customCoinMap = coins) =>
520542
customCoinMap.reduce((acc: SolTokenConfig[], coin) => {
521543
if (coin instanceof SolCoin) {
@@ -742,6 +764,9 @@ export const getFormattedTokens = (coinMap = coins): Tokens => {
742764
bera: {
743765
tokens: getFormattedBeraTokens(coinMap).filter((token) => token.network === 'Mainnet'),
744766
},
767+
coredao: {
768+
tokens: getFormattedCoredaoTokens(coinMap).filter((token) => token.network === 'Mainnet'),
769+
},
745770
apt: {
746771
tokens: getFormattedAptTokens(coinMap).filter((token) => token.network === 'Mainnet'),
747772
nftCollections: formattedAptNFTCollections.filter(
@@ -824,6 +849,9 @@ export const getFormattedTokens = (coinMap = coins): Tokens => {
824849
stx: {
825850
tokens: getFormattedSip10Tokens(coinMap).filter((token) => token.network === 'Testnet'),
826851
},
852+
coredao: {
853+
tokens: getFormattedCoredaoTokens(coinMap).filter((token) => token.network === 'Testnet'),
854+
},
827855
},
828856
};
829857
};

0 commit comments

Comments
 (0)